Format and beautify nginx config files via this module
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 7 commits ahead, 7 commits behind vasilevich:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
nginxbeautify
.gitignore
LICENSE
README.md
package.json

README.md

nginx config file formatter and beautifier

This module beautifies and formats Nginx configuration files like so:

  • all lines are indented in uniform manner, with 4 spaces per level
  • neighbouring empty lines are collapsed to at most two empty lines
  • curly braces placement follows Java convention
  • whitespaces are collapsed, except in comments an quotation marks

Need to format quickly?

Use vasilevich website: nginxbeautifier.com

Instructions

npm install nginxbeautify

const fs = require('fs');

let file = fs.readFileSync(__dirname + '/nginx.conf').toString();
let Beautify = require('nginxbeautify');
let instance = new Beautify({tabs: 1});

console.log(instance.parse(file));

Options

let Beautify = require('nginxbeautify');
let instance = new Beautify({
    spaces: 0,
    tabs: 0,
    dontJoinCurlyBracet: true
});

Credits

Michał Słomkowski - Original code was ported from their project(nginxfmt.py), and also used their readme.md as a template. Some methods were rewritten or changed a bit, but most of the code follows their design.

Yosef - Porter of the Python code to js: check out his awesome nginxbeautifier from where this project was forked from.

Denys Vitali - Creator of this module

Notes:

I am keeping the same licenese format as the one that was given by the owner of the project the code was ported from: Apache 2.0.