A parser and code generator for NGINX configuration files
var parser = require('nginx-config-ast');
var config = `
server {
listen 80;
server_name example.com;
location / {
root /etc/nginx/html;
try_files $uri $uri/ $uri.html =404;
}
}
`;
// You can convert the configuration into an abstract tree (AST)
var ast = parser.generateAST(config);
// You can also convert the AST back to a configuration
var code = parser.generateConfig(ast);
Checks if the configuration is valid and returns a boolean.
config
: string - Code of a NGINX configuration file
Generates and returns an abstract tree for specified configuration code.
config
: string - Code of a NGINX configuration fileoptions
: objectnoComments
: boolean - Strips all comments from the AST
Generates and returns configuration code from an abstract tree.
ast
: object - Abstract tree for an NGINX configuration- See src/parser.d.ts for typings