{"id":20392,"library":"prettier-plugin-nginx","title":"Prettier for NGINX","description":"prettier-plugin-nginx is a Prettier plugin that formats NGINX configuration files (.nginx, .nginxconf). Version 1.0.3 ships TypeScript types and targets modern Prettier (v2+). It is written in TypeScript and depends only on Prettier. Differentiators: opinionated formatting with configurable alignment, parameter wrapping, and continuation indentation; supports standard NGINX directives but not extensions like lua-nginx-module. Release cadence is low; last release was 2024.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/joedeandev/prettier-plugin-nginx","tags":["javascript","nginx","prettier","prettier-plugin","configuration","format","autoformat","autoformatter","typescript"],"install":[{"cmd":"npm install prettier-plugin-nginx","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-nginx","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-nginx","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency – used as the formatting engine","package":"prettier","optional":false}],"imports":[{"note":"Plugin is used via Prettier API, not direct default import. Use Prettier's resolver.","wrong":"const prettier = require('prettier-plugin-nginx')","symbol":"default","correct":"import prettier from 'prettier-plugin-nginx'"},{"note":"Pass the plugin name string to Prettier options; Prettier resolves it.","wrong":"const options = { plugins: [require('prettier-plugin-nginx')] }","symbol":"Pugins","correct":"import * as prettier from 'prettier'; const options = { plugins: ['prettier-plugin-nginx'] }"},{"note":"Named exports for options available since v1. Prettier imports these via plugin options.","wrong":"const alignUniversally = require('prettier-plugin-nginx').alignUniversally","symbol":"alignUniversally","correct":"import { alignUniversally } from 'prettier-plugin-nginx'"}],"quickstart":{"code":"import prettier from 'prettier';\nimport nginxPlugin from 'prettier-plugin-nginx';\n\nconst code = `server {\n    listen 80;\n    server_name example.com;\n    location / { proxy_pass http://proxy; } }`;\n\nprettier.format(code, {\n  parser: 'nginx',\n  plugins: [nginxPlugin],\n  alignDirectives: true,\n  wrapParameters: true\n}).then(result => console.log(result));","lang":"typescript","description":"Formats an NGINX config string using Prettier with the plugin, enabling directive alignment and parameter wrapping."},"warnings":[{"fix":"Avoid using with configs containing Lua blocks, or handle those manually.","message":"Plugin does not support lua-nginx-module or other multi-language extensions; embedded code will break.","severity":"gotcha","affected_versions":"all"},{"fix":"Set parser to 'nginx' in Prettier options or rename files.","message":"Plugin only formats .nginx and .nginxconf files by default; other extensions require explicit parser override.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to v1.0.0+ and use named exports like `alignUniversally` if needed.","message":"v1.0.0 introduced named exports for configuration options; previous versions used plugin-local options only.","severity":"breaking","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install --save-dev prettier-plugin-nginx`","cause":"Plugin not installed or not in node_modules.","error":"Error: Cannot find module 'prettier-plugin-nginx'"},{"fix":"Ensure Prettier >=2.0 and pass plugin via `plugins` array.","cause":"Prettier version <2.0 or plugin not loaded properly.","error":"[error] Invalid parser option: 'nginx'"},{"fix":"Use `import prettier from 'prettier'` (ESM) or `const prettier = require('prettier')` (CJS).","cause":"Using wrong import (default vs named) for Prettier.","error":"TypeError: prettier.format is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}