Registry / devops / nginx-config-formatter

nginx-config-formatter

JSON →
library1.4.5jsnpmunverified

CLI and API formatter for Nginx configuration files. Version 1.4.5, released under MIT license. Ships TypeScript types. Differentiated from nginxbeautifier by adding empty line trimming after '{' and before '}', TypeScript API, and test consistency. Supports glob patterns, indent style (space/tab), alignment, and trailing blank lines. Requires Node >=14.18.0.

npm install nginx-config-formatter
INSTALL
IMPORT
SIG · NGINX-CONFIG-FORMA
N
nginx-config-formatter
devopsjavascriptv1.4.5
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.

formatFile
import { formatFile } from 'nginx-config-formatter'
const formatFile = require('nginx-config-formatter').formatFile
Works in ESM and CJS (dual package). TypeScript types included.
formatContent
import { formatContent } from 'nginx-config-formatter'
import formatContent from 'nginx-config-formatter'
Named export, not default.
OptionType
import type { OptionType } from 'nginx-config-formatter'
TypeScript only, used for type safety with options objects.

Demonstrates both formatFile and formatContent usage with options.

// Format /etc/nginx recursively import { formatFile } from 'nginx-config-formatter'; await formatFile('/etc/nginx', { indentStyle: 'space', dontJoinCurlyBracket: false, align: false, trailingBlankLines: false, extension: 'conf' }); // Format a single file string import { formatContent } from 'nginx-config-formatter'; const raw = `server { listen 80; server_name example.com; }`; const formatted = formatContent(raw, { indentStyle: 'tab' }); console.log(formatted);
Debug
Known issues
gotchaformatFile with a directory will format all .conf files recursively without warning.
fix
Ensure you intend to format all .conf files in the directory tree, or specify a single file.
affects: >=1.0
gotchaOptions object properties are optional but if provided with incorrect types (e.g., string instead of boolean) they may be silently ignored.
fix
Use TypeScript or ensure option types match the OptionType interface.
affects: >=1.0
deprecatedformatContent does not validate the input; invalid config may produce malformed output.
fix
Validate your config beforehand or use nginx -t to check syntax.
affects: >=1.0
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, scandir '/etc/nginx'
Path does not exist or permissions missing.
fix
Check that the path exists and that the process has read permissions.
TypeError: formatFile is not a function
Default import used instead of named import.
fix
Change to import { formatFile } from 'nginx-config-formatter'.
Cannot find module 'fast-glob'
Missing dependency fast-glob (should be installed automatically but may be missing in some environments).
fix
Run npm install fast-glob or reinstall the package.
Upgrade
Version history
1.4.5latest on npm
Audit
Dependencies
fast-globrequiredGlob pattern matching for file paths
Agent activity
2 hits · last 30 days
node
2
Resources
nginx-config-formatter — npm install nginx-config-formatter · libregistry