npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nginx-pretty

v1.0.9

Published

git init

Downloads

972

Readme

🛡️ nginx-pretty

A CLI utility to safely format and apply NGINX configuration files using the nginxbeautifier package (same as bash.sh). Never modifies original files unless you confirm; shows diff and validates with nginx -t.


🚀 Features

  • 📄 Run on default config only with --default/-d; custom path via --file. Running with no target shows help (safer).
  • 🛡️ Never modifies the original unless confirmed
  • 🔍 Shows unified diff before applying
  • 🧪 Runs nginx -t to validate before reload
  • 🧰 Works with sudo, in disconnected or hardened servers
  • 🧱 CLI structure is standalone, can be bundled with pkg

🧱 Directory Structure

nginx-pretty/
├── cli.js                         # Main script (uses nginxbeautifier)
├── bin/
│   └── nginx-pretty               # Optional wrapper bash script
├── README.md
├── package.json

⚙️ Usage

Global install (recommended)

Install globally with npm. Run as your user (so your PATH/nvm is used); the CLI uses sudo only when copying to the config file and when running nginx -t:

npm install -g nginx-pretty
nginx-pretty --default   # or -d to use /etc/nginx/sites-available/default

Running nginx-pretty with no options shows help only; use --default/-d or --file <path> to target a config.

If you use nvm and install with npm install -g nginx-pretty, do not run with sudo nginx-pretty (sudo uses root’s PATH and won’t see nvm). Run nginx-pretty as your user; you may be prompted for your password when the tool runs sudo cp and sudo nginx -t.

As Bash Script (with embedded Node)

./bin/nginx-pretty

Via npx

npx nginx-pretty

If Bundled as a Binary (using pkg)

./nginx-pretty

Options

| Option | Description | |--------|-------------| | --default, -d | Use the default config file (/etc/nginx/sites-available/default) | | --file, -f <path> | Config file path | | --check-only | Show diff only, do not prompt or apply | | --dry-run | Same as --check-only | | --no-prompt | Apply without prompting (for CI; use with caution) | | --help, -h | Show help |

Running nginx-pretty with no options (or with only --help/-h) shows help and exits; you must pass --default/-d or --file <path> to run on a config.

Help

nginx-pretty          # shows help (no target)
nginx-pretty --help   # or -h

📜 Example Flow

🧪 Running nginx-pretty...
📄 Copying original file to: /tmp/tmp_nginx_formatted.conf
🆕 Ensuring temp file is writable...
🎨 Formatting the copied config...

🔍 Showing unified diff (ORIGINAL vs FORMATTED):
...
diff output...

⚠️  Do you want to apply the formatted config? (yes/no): yes
🚀 Config test passed. You can now reload NGINX
   Run: sudo service nginx reload to apply the changes

🛠️ Build Instructions (Optional)

To package this into a true standalone binary:

npm install
npm install -g pkg
pkg cli.js --output nginx-pretty

Or use the npm script:

npm run build:pkg

✅ This produces a native binary: no Node required on the target machine.


🧪 How to test

From the project directory (no global install needed):

1. Help

node cli.js --help

2. Dry-run (no nginx required)
Use a temporary config so nothing is modified. You should see a unified diff and “Dry run / check-only: not applying.”

echo 'server { listen 80; root /var/www; }' > /tmp/test-nginx.conf
node cli.js --file /tmp/test-nginx.conf --dry-run

3. Optional: real NGINX config
If you have NGINX and a config (e.g. /etc/nginx/sites-available/default), run with --dry-run first to only view the diff:

sudo node cli.js --file /etc/nginx/sites-available/default --dry-run

Without --dry-run, the CLI will prompt to apply; answer yes only if you want to overwrite the file.


🔐 Security Notes

  • This CLI never overwrites original config unless approved.
  • Temporary files are cleaned and written to /tmp.
  • Requires sudo for NGINX reload steps.
  • Uses spawn with array arguments only; no user input is passed to shell.

📦 Dependencies

  • nginxbeautifier (npm dependency; same formatter as bash.sh)
  • Node.js 14+
  • diff on PATH (for unified diff; standard on Linux)

📜 License

MIT © You