Fill in the form and get a clean, valid package.json as you type. The name, version, dependency ranges and repository are checked against npm's rules, and you can start from a preset or import an existing file.
Last updated:
package.json
Save the file in your project root and run npm install (or pnpm install / yarn) to create the lock file.
Advertisement
Advertisement
How to use the package.json Generator
Pick a preset (optional) such as Node library, Express API or Vite React app to fill sensible defaults.
Fill in the basics: package name, version, description, author, license and module type (CommonJS or ES modules).
Add scripts with the quick buttons or type your own name and command pairs.
List dependencies one per line as name@range, for example express@^4.21.2.
Check the validation panel, then copy the JSON or download package.json and run npm install.
package.json fields at a glance
Field
What it does
Example
name
Package name on npm and in import/require. Lowercase, URL-safe, max 214 characters.
"@acme/utils"
version
Semantic version MAJOR.MINOR.PATCH, with optional pre-release and build tags.
"2.1.0-beta.1"
private
When true, npm publish refuses to publish the package.
true
type
"module" makes .js files ES modules; "commonjs" (the default) keeps require.
"module"
main
Entry file loaded by require('pkg') when there is no exports field.
"./dist/index.js"
exports
Modern entry point map. It also hides every file that is not exported.
"./index.js"
types
TypeScript declaration file for the main entry.
"./dist/index.d.ts"
bin
Commands installed on the PATH. The file needs a #!/usr/bin/env node first line.
{"mycli": "./bin/cli.js"}
files
Allow-list of files included when publishing. package.json, README and LICENSE are always included.
["dist"]
scripts
Commands for npm run <name>. start and test also work as npm start and npm test.
{"dev": "vite"}
engines
Supported Node.js versions. npm warns (or fails with engine-strict) on others.
>=0.3.1 and <0.4.0 (for 0.x the caret only allows patch updates)
~4.21.2
>=4.21.2 and <4.22.0 (patch updates only)
4.x or 4
Any 4.y.z version
>=18 <23
Both conditions (AND)
^16 || ^18
Either range (OR)
1.2.0 - 1.4.5
Inclusive hyphen range
* or latest
Any version / the version tagged latest (not reproducible, avoid in apps)
workspace:*, file:../lib, github:user/repo
Monorepo workspace, local folder or Git dependency
Tips for a clean package.json
Applications and websites should set "private": true and commit the lock file so every install gets identical versions.
Libraries should keep runtime dependencies small, put tooling in devDependencies, and use peerDependencies for frameworks the host app already has, such as React.
Use files (or an .npmignore) so tests, sources and configs are not published. Check what ships with npm pack --dry-run.
Lifecycle scripts run automatically: prepare runs after npm install and before publishing, prepublishOnly only before npm publish, and pre<name>/post<name> wrap any script.
Bump versions with npm version patch|minor|major, which also creates a Git tag.
Frequently asked questions
What fields does a package.json need?
Only name and version are required if you publish the package to npm. For a private application nothing is strictly required, but name, version, private: true, scripts and dependencies are standard. Description, license, repository and author help others understand the project.
What are the rules for an npm package name?
The name must be 214 characters or fewer including the scope, lowercase, URL-safe (letters, digits, -, ., _ and ~), and must not start with a dot or underscore or contain spaces. Scoped names look like @scope/name. Core Node module names such as http or fs are not allowed.
What does "type": "module" do?
It tells Node.js to treat .js files in the package as ES modules, so you use import and export instead of require and module.exports. Without it, or with "type": "commonjs", .js files are CommonJS. You can always force a format with the .mjs or .cjs extension.
What is the difference between ^ and ~ in versions?
A caret range like ^4.21.2 allows any later version with the same major number (4.x.x, at least 4.21.2). A tilde range like ~4.21.2 only allows patch updates (4.21.x). An exact version like 4.21.2 pins one release. For 0.x versions the caret is stricter and allows only patch updates within the same minor version.
dependencies vs devDependencies vs peerDependencies?
dependencies are needed at runtime and are installed for anyone who installs your package. devDependencies are only needed while developing or building (test runners, linters, bundlers). peerDependencies declare a package that the host project must provide, such as react for a React component library.
Why set "private": true?
It stops npm publish from ever publishing the package by accident. Use it for applications, websites and monorepo roots that are not meant to be on the npm registry.
Is my data uploaded?
No. The package.json is built and validated entirely in your browser. Your last form state is saved only in this browser's local storage.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.