Registry / devops / nginx-format

nginx-format

JSON →
library0.1.8jsnpmunverified

A pure JavaScript formatter for NGINX configuration files, version 0.1.8. It indents, splits long directives, and normalizes whitespace. Ships with TypeScript definitions. No runtime dependencies. Unlike nginxbeautifier (Python) or nginx-config-formatter (Java), this is a lightweight Node.js library suitable for CLI or build tool integration. Development appears slow; last update was in 2022. Works in Node.js only (not browser). Supports customizable indentation and maximum line length.

npm install nginx-format
INSTALL
IMPORT
SIG · NGINX-FORMAT
N
nginx-format
devopsjavascriptv0.1.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

nginxFormat
import { nginxFormat } from 'nginx-format'
const nginxFormat = require('nginx-format').nginxFormat
ESM named import; CommonJS requires destructuring
default
import nginxFormat from 'nginx-format'
const nginxFormat = require('nginx-format')
Library has a default export that is the named function; both work but prefer named import
NginxFormatOptions
import type { NginxFormatOptions } from 'nginx-format'
TypeScript-only; not exported as value

Reads an NGINX config file, formats it with 2-space indentation, and writes the result.

import { nginxFormat } from 'nginx-format'; import { readFileSync, writeFileSync } from 'fs'; const config = readFileSync('/etc/nginx/nginx.conf', 'utf8'); const formatted = nginxFormat(config, { indent: ' ', newLineSeparator: '\n', maxStatementLength: 80 }); writeFileSync('nginx-formatted.conf', formatted); console.log('Formatted successfully');
Debug
Known issues
gotchaThe formatter may strip comments that are not on their own line (e.g., inline comments after directives).
fix
Ensure comments are placed on separate lines before formatting.
affects: >=0.0.0
gotchaDoes not validate syntax; malformed input may produce silently incorrect output.
fix
Validate config with nginx -t before formatting.
affects: >=0.0.0
gotchaThe package has not been updated since 2022; consider forking or using alternatives like nginxbeautifier.
fix
Evaluate if maintenance status meets your needs.
affects: <=0.1.8
Errors
Common errors & fixes
TypeError: nginxFormat is not a function
Using default import when library expects named import or vice versa.
fix
Use `import { nginxFormat } from 'nginx-format'`
Cannot find module 'nginx-format'
Package not installed or import path incorrect.
fix
Run `npm install nginx-format` and ensure import path is exactly 'nginx-format'.
Upgrade
Version history
0.1.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
12
Resources
nginx-format — npm install nginx-format · libregistry