v26.5.0 Jul 8 · yesterday · Releases

Node

Node is a runtime environment for Javascript and Typescript.

Installing Node

Terminal window
npm init

package.json

package.json
{
"name": "project-name",

The Name of the package

  • Must be lowercase and URL-safe
"version": "1.0.0",

The Version of the package

  • Must be a semantic version 0.0.0-tag
Publishing — 2 collapsed lines
"private": false,
"publishConfig": {},
Metadata — 20 collapsed lines
"description": "An awesome project",

The description of the package

"keywords": ["node", "javascript", "npm"],

Keywords to help discover the package

"homepage": "https://username.me/project",

The Website of the project

"repository": {
"type": "git",

The Version Control System

  • git Git
  • svn Apache Subversion
  • hg Mercurial
"url": "https://github.com/OWNER/REPO",

The URL of the project's Repository

"directory": "subproject/src"

The Directory of the package

},
"bugs": {
"url": "https://github.com/OWNER/REPO/issues",

The URL of the project's Issue tracker

"email": "contact@username.me"

The Email to which issues should be reported

},
"license": "ISC",

The License of the project

  • Defaults to ISC

Choosing the right license

"author": "Name <contact@username.me> (https://username.me)",

The author of the project

"contributors": [

The Contributors of the project

{ "author": "Notch" },
{ "author": "Gabe Newell" },
{ "author": "Hideo Kojima" }
],
"funding": "https://www.paypal.com/paypalme/stephcraft64",

Some URL to the project's Funding page

Bundle — 8 collapsed lines
"files": ["*"],

Specify which files to include in the package's distribution

  • Defaults to * all files
  • Alternatively, an .npmignore can be used instead
"directories": {},

Legacy use bin, man, main instead

"bin": {

Can be used to define entrypoints for npx commands

"greeting": "hi.js"
},
"man": "./man/tool.1",

Can be used to define Documentation for the man command
Arch Linux Wikiman page

"exports": {},

Can be used to define multiple entrypoints

"browser": "browser-index.js",

Alternative entrypoint that runs in the browser

"main": "index.js",

The primary entrypoint of the package

"type": "commonjs",

The module syntax to use

  • "commonjs" — Allows require() and module.exports syntax
  • "module" — Allows import/export syntax
"scripts": {

Scripts which can be run with npm run <script>

"start": "node index.js"
},
"config": {

Environment variables can be defined

  • They are prefixed with npm_package_config_*
"port": "8080"
},
"dependencies": {},
"devDependencies": {},
Advanced Dependencies — 6 collapsed lines
"peerDependencies": {},
"peerDependenciesMeta": {},
"bundleDependencies": {},
"optionalDependencies": {},
"overrides": {},
"gypfile": true,

Whether to use node-gyp when using a binding.gyp file

Environment Dependencies — 19 collapsed lines
"engines": {

pnpm, yarn

"node": "",
"npm": ""
},
"os": [],
"cpu": [],
"libc": "glibc",

C Library (Linux)

"devEngines": {
"runtime": {
"name": "node",
"version": "",
"onFail": "error | warn | ignore | download"
},
"packageManager": {
"name": "npm",
"version": "",
"onFail": "error | warn | ignore | download"
},
}
}

NPM Docs — package.json
JSON Schema — package.json

npm

unscoped package-name
scoped @username/package-name
  • Create an npm account
  • Run npm login
  • Run npm publish --access public

This website is currently available on Desktop only
Let @Stephcraft know on Discord you'd like a Mobile version

Join Discord