📦 package.json Generator
Fill the wizard on the left, get your perfect package.json on the right
Basic Info
Scripts
dependencies
devDependencies
{
"name": "my-project",
"version": "1.0.0",
"description": "A Node.js project",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "jest",
"dev": "nodemon index.js",
"lint": "eslint ."
},
"license": "MIT",
"dependencies": {
"express": "^4.18.0"
},
"devDependencies": {
"jest": "^29.0.0",
"eslint": "^8.0.0"
},
"engines": {
"node": ">=18.0.0"
}
}📊 Key Data Points
exports field
Controls what ESM/CJS is exposed — overrides main in Node.js 12.7+
SPDX identifiers
Required for npm and license scanning tools
private: true
Prevents accidental publish — essential for internal and monorepo packages
package.json Generator -- Complete USA Guide 2026
Every Node.js project starts with a package.json. Writing it from scratch means remembering exact field names for exports, type, engines, peerDependencies, and scripts. Errors cause import failures and npm publish issues.
This generator builds a correctly structured package.json from form inputs. Runs in your browser.
**Long-tail searches answered here:** generate package.json online for npm package free, npm package.json builder with exports field, create node package.json correct format browser tool.
Pair with Semver Calculator for version ranges.
🔬 How This Calculator Works
Builds valid JSON following npm package.json spec. Required: name (kebab-case), version (semver), description. Common optional fields: main, module, exports, type, scripts, dependencies, devDependencies, peerDependencies, engines, license, keywords, repository. The exports field is generated with conditional exports for ESM, CJS, and TypeScript declarations simultaneously — the most complex and frequently misconfigured part.
✅ What You Can Calculate
Correct exports field
Generates modern conditional exports for ESM, CJS, and TypeScript types — the most error-prone part of package.json configuration for npm packages.
ESM vs CJS configuration
Sets type: module for ESM packages and generates correct file extensions (.mjs/.cjs) for dual-module packages.
engines field validation
Generates engines field with correct semver range format like node >=18.0.0 — prevents install on unsupported Node.js versions.
SPDX license identifiers
Uses correct SPDX identifiers (MIT, Apache-2.0, GPL-3.0) — required for public npm packages and read by license scanning tools.
🎯 Real Scenarios & Use Cases
Starting a new npm package
Generate a complete package.json with all standard fields. Faster than npm init -y plus 10 manual field edits.
Dual ESM/CJS package setup
Publishing a package that works for both import and require? The generator creates the correct exports field structure.
Private internal package
Set private: true to prevent accidental npm publish. Configure org-scoped name (@myorg/package-name).
Monorepo workspace config
Generate package.json for workspace packages with correct cross-package dependency references.
💡 Pro Tips for Accurate Results
Package names must be lowercase kebab-case. my-package is valid; MyPackage and my_package are not — npm rejects uppercase and underscores.
exports field overrides main. In Node.js 12.7+, the exports field takes precedence. Callers can only import what you explicitly export.
peerDependencies vs dependencies. If your package requires React but does not bundle it, list it as peerDependencies — prevents version conflicts in apps that already have React installed.
Validate after editing. Paste the generated package.json into JSON Formatter to confirm valid JSON before using it.
🔗 Use These Together
🏁 Bottom Line
Getting exports, module type, and version ranges right the first time prevents hours of import failures. For the full Node.js project setup: generate package.json here, search packages with npm Package Search, and manage constraints with Semver Calculator.
What are the required fields in a package.json?
Strictly speaking, only name and version are required for a published npm package. name must be lowercase, no spaces, under 214 characters (use hyphens: my-package). version must follow semver (1.0.0). For applications (not published to npm), no fields are strictly required — but a minimal useful package.json includes: name, version, description, main (entry point), scripts (run commands), and author. For npm publishing, add: keywords, repository, license, and homepage.
What is the difference between 'main', 'module', and 'exports' in package.json?
main: the CommonJS entry point (require('package') resolves this). module: the ES Module entry point (non-standard but widely supported by bundlers). exports: the modern way to define conditional exports — different files for different conditions (import vs require, browser vs node, development vs production). Use exports for new packages: { exports: { import: './esm/index.js', require: './cjs/index.js' } }. Bundlers like webpack and Rollup respect exports. Node.js respects exports for require() and import as of v12+.
What is the 'engines' field and should I include it?
engines specifies which Node.js (and npm) versions your package supports: { engines: { node: '>=18.0.0', npm: '>=9.0.0' } }. npm does not enforce this by default — it warns but does not block installation. To enforce: set engine-strict=true in .npmrc. Always specify engines when your package uses APIs only available in certain Node.js versions (fetch natively in Node 18+, crypto.webcrypto in Node 15+). For monorepos managed with pnpm or yarn workspaces, engines is enforced more strictly.
What scripts should every package.json have?
Essential scripts: start (run the application: node src/index.js or nodemon), build (compile/bundle: tsc || webpack || vite build), test (run tests: jest || vitest || mocha), lint (check code quality: eslint . || biome check .), dev (development server with hot reload: nodemon || vite || next dev). Optional but recommended: typecheck (tsc --noEmit for TypeScript without building), format (prettier --write .), clean (rm -rf dist), prepare (runs before npm publish: build). Scripts prefixed with pre/post run automatically before/after the named script.
What is the 'private' field and when should I set it?
private: true prevents accidental npm publish. Always set private: true for: application repositories (not libraries), internal packages in monorepos that should not be published publicly, and any project where npm publish would be a mistake. Without private: true, running npm publish in any package.json directory would attempt to publish to the npm registry. For monorepos: the root package.json should have private: true; individual publishable packages within the monorepo may not.
How do version range specifiers work in package.json dependencies?
^1.2.3 (caret): accepts 1.x.x where x >= 2.3 — minor and patch updates allowed. ~1.2.3 (tilde): accepts 1.2.x where x >= 3 — only patch updates allowed. 1.2.3 (exact): only exactly that version. >=1.2.3 <2.0.0: explicit range. * or latest: any version (dangerous in production). The Semver Calculator on this site shows exactly which versions any range expression matches. For production dependencies: use ^ (caret) for flexibility while maintaining major version stability. For tooling in devDependencies: ^ is usually fine.
What other project setup tools are on this site?
The npm Package Search finds the packages to add to your package.json. The Semver Calculator verifies version ranges. The Gitignore Generator creates .gitignore for Node.js projects. The Git Commit Generator follows Conventional Commits for npm package versioning. The JSON Formatter validates and reads package.json and package-lock.json. All are in the Dev Tools section.