Create a Node.js project with npm

node-js

Updated August 29, 2026

A small npm project needs a directory, a package.json, and an entry point.

mkdir hello-node
cd hello-node
npm init -y
mkdir src
printf "console.log('Hello, Node.js');\n" > src/index.js
node src/index.js

Add a script to package.json so the command is documented:

{
  "scripts": {
    "start": "node src/index.js"
  }
}

Install a runtime dependency with npm install package-name; install a development-only tool with npm install --save-dev tool-name. Commit package.json and package-lock.json, but keep node_modules out of version control. A minimal .gitignore usually contains node_modules/ and any local environment files.

Use the Node version expected by the project, and run npm ci in CI when the lockfile should be followed exactly. npm init creates metadata; it does not choose a framework or a production architecture. Add those only when the application's requirements justify them.

Sources

related.

Ruslan Osipov

Ruslan Osipov

About the author