This episode separates the roles of node as the runtime, npm as the package manager, and npx as the package launcher. You learn the structure of package.json, semver, how to add dependencies, and how to run tools temporarily without a global install.

The three commands you'll type most often in the Node.js world are node, npm, and npx. Their names are similar, but their roles are very different. node runs JavaScript, npm manages packages, and npx runs packages without installing them permanently.
Episode 2 makes sure you master all three. We'll look at how the node command works for evaluation and REPL, the structure of package.json as the center of a project, the semver rules for version selection, and how to leverage npx for tools like tsc and create-next-app.
The most common way to use node is to run a script file. In addition, node has useful flags for quick evaluation:
node hello.js
node -e "console.log('Jalankan tanpa file')"
node -p "1 + 1"The -e flag evaluates code directly, while -p evaluates and then prints the result like a REPL. So node -p "1 + 1" immediately prints 2 without needing a console function. Both flags are very practical for quick experiments in the terminal.
Type node without arguments to enter the REPL — an interactive shell where you type JavaScript and see the result right away. Type process.exit() to leave.
For development, Node.js also provides a built-in watch mode:
node --watch app.jsThe mode node --watch app.js watches files and restarts the program on every change — a nodemon replacement now available directly from Node.js with no extra dependencies.
package.json is the heart of every Node.js project. This is where the name, version, scripts, and dependencies are recorded. You can create it with npm init -y, or read and modify its contents directly:
npm init -y
cat package.jsonThe most important fields at the start:
npm run.Don't use npm run only for built-in commands — it's the standard way to store repetitive commands:
{
"name": "belajar-nodejs",
"version": "1.0.0",
"scripts": {
"start": "node app.js",
"dev": "node --watch app.js"
}
}With the definitions above, you run npm run dev for development and npm start for production. These scripts can hold any command — including the build and test tools we'll discuss in episode 18.
To add a package, use npm install:
npm install express
npm install --save-dev vitestnpm install express adds Express to dependencies, while --save-dev adds it to devDependencies. When working in a team, the command npm install --frozen-lockfile (matching the lockfile) ensures every team member uses exactly the same dependency versions.
Every package version on npm follows semver: major.minor.patch. Version 2.3.1 means major 2, minor 3, patch 1. Breaking changes raise the major, new features raise the minor, and bug fixes raise the patch.
In package.json, dependencies are written with version ranges like ^5.0.0, which means it may move up to the latest minor and patch within major 5, but won't jump to major 6. This is why the lockfile matters: version ranges may widen, but the lockfile locks the versions actually installed.
npx launches a package from the registry without installing it permanently. This is ideal for one-off CLI tools:
npx tsc --version
npx create-next-app@latest situs-saya
npx express-generator api-sayaThe command npx tsc --version temporarily downloads TypeScript and then runs its compiler — without flooding your machine with global installs. For a specific version, add a tag like create-next-app@latest to always use the latest release.
The rule is simple: use npm to manage the project dependencies you use constantly, and npx to run one-off tools. If a CLI is used every day across many projects, then consider npm install -g to install it globally.
Here's what to take away:
node runs JavaScript; -e and -p are for quick evaluation.node --watch replaces nodemon for auto restart.package.json stores project metadata, scripts, and dependencies.npm install adds dependencies; --save-dev is for tooling.major.minor.patch determines version bumping rules.npx runs packages temporarily without a global install.In the next episode, episode 3, we'll discuss Node.js core modules — fs for the file system, path for path manipulation, os for system information, and events for EventEmitter. You'll see the built-in modules that form the foundation of every Node.js backend application.