nginx-conf is a node module for making changes to an nginx configuration
npm install nginx-conf
There are no dependencies and this library is tested on node v0.8 - v8.
Pretend you have an nginx config file like this one.
Note that all public methods are prefixed with
_ so that they (hopefully) don't clash with
*_content_by_lua_block directives are supported in
var NginxConfFile = NginxConfFile;NginxConfFile;
Support for comments is supported-ish. Comments are attached to directives, and will always
be rendered above the directive when using
Comments can be added, removed and updated via the
_comments array on a node.
console; // 1console; // use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];//remove the commentconfnginxeventsuse_comments;//add a new oneconfnginxeventuse_comments;console; // 1console; //my new comment//update a comment's textconfnginxeventuse_comments0 = 'updated';console; //updated
If the comment is in a weird place (like in the middle of a directive), it'll still be attached to the node. If it's after the directive (after the semicolon or closing brace), it will be attached to the next node, or ignored if it's at the end of the file.
Assuming this nginx configuration:
foo #comment bar;
You will have this object structure:
console; //barconsole; //comment
But if the comment comes after:
foo bar; #comment
console; //barconsole; //0
git clone email@example.com:tmont/nginx-conf.git cd nginx-conf npm install npm test