package.json generator — scripts, dependencies and metadata

Fill in the name, version, scripts and dependencies, and the tool writes a package.json for a Node.js project or npm package, checks the package name and warns about duplicate dependencies.

Live demo · real result from this tool
Module type

package.json

{  "name": "invoice-parser",  "version": "1.0.0",  "description": "Extracts data from PDF invoices",  "keywords": [    "pdf",    "invoice",    "parser"  ],  "license": "MIT",  "author": "Asha Rao <asha@example.com>",  "repository": {    "type": "git",    "url": "git+https://github.com/asharao/invoice-parser.git"  },  "type": "module",  "main": "dist/index.js",  "exports": {    ".": "./dist/index.js"  },  "scripts": {
    "build": "tsc",
    "test": "vitest run",
    "lint": "eslint ."
  },
  "dependencies": {
    "pdfjs-dist": "^5.4.0"
  },
  "devDependencies": {
    "eslint": "^10.0.0",
    "typescript": "^7.0.0",
    "vitest": "^4.0.0"
  },
  "engines": {
    "node": ">=22"
  }
}

Processed on your device — nothing is uploaded.

How to use the package.json generator

  1. Enter the Name, Version and Description.
  2. Choose the Module type: ES modules or CommonJS. Set Licence (SPDX), Author and Repository (owner/name or URL).
  3. Add Keywords (comma-separated) and the Entry point, such as dist/index.js.
  4. List Scripts (name: command), one per line, then Dependencies (name@version) and Dev dependencies (name@version).
  5. Set the Node.js engines range, tick Private (never published) if needed, and copy the JSON into package.json.

What it does and when to use it

Every Node.js project and npm package has a package.json. It names the project, lists the packages it needs and defines commands such as npm test. By hand it is easy to slip: a missing comma, an upper-case name, or a repository URL npm does not recognise.

Use it to start a project or tidy an old file. The scripts you define are the ones the GitHub Actions generator calls. Put the same SPDX id in the licence generator, and add the matching compiler settings with the tsconfig generator. To check a file you already have, paste it into the JSON validator.

How it works

The tool builds a JSON object in a fixed field order and prints it with two-space indentation:

  • Name check: the npm rules for new packages, at most 214 characters, lower-case, URL-safe characters only, no leading dot or underscore. Problems appear as a warning under the file.
  • Repository: owner/name becomes git+https://github.com/owner/name.git; a full https URL gets the git+ prefix and .git ending.
  • Entry point: sets both main and an exports entry for ".".
  • Dependencies: each line can be name@^1.2.3, @scope/name@1.0.0, name: ^1.2.3 or name 1.2.3. Lists are sorted, and a package in both lists is flagged.

The npm documentation for package.json describes every field.

Worked examples

The default library. With the starting values, the repository becomes:

"repository": {
  "type": "git",
  "url": "git+https://github.com/asharao/invoice-parser.git"
}

and "main": "dist/index.js" is paired with "exports": { ".": "./dist/index.js" }.

An invalid name. Name My Package still produces a file, with two warnings: “New package names must be lower-case.” and a note that names may contain only URL-safe characters.

A private scoped CLI. Name @northwind/cli-tools, CommonJS, no entry point, Private ticked, repository https://gitlab.com/northwind/cli-tools, dependencies chalk 5.4.1 and commander: ^14.0.0, and commander again as a dev dependency. The URL becomes git+https://gitlab.com/northwind/cli-tools.git, and a warning says commander is listed in both lists.

Limits and tips

  • Review exports. With an exports map, other code can import only the paths listed there.
  • Fields not in the form, such as bin, files or workspaces, must be added by hand.
  • Never put tokens in scripts. Use environment variables instead.

Frequently asked questions

Is this the same as running npm init?
It makes the same kind of file, but you edit every field at once and get exports, engines and a normalised repository URL.
Which version numbers should I write for dependencies?
Use the range you want npm to accept, for example ^5.4.0 for any 5.x release from 5.4.0 on. If you give only a name, the tool writes "latest". It does not look up current versions, so check them on the npm registry or let npm install fill them in.
What does Private do?
It adds the private flag set to true, which makes npm refuse to publish the package. Tick it for apps and internal projects that should never reach the public registry.
ES modules or CommonJS?
ES modules (type set to "module") let .js files use import and export. CommonJS keeps require and module.exports. New projects usually choose ES modules; pick CommonJS only for older code or tools that need it.
Why are my dependencies in a different order?
The tool sorts both dependency lists alphabetically, as npm does when it saves them.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close