Getting started with Node.js involves installing the runtime, initializing standard configuration files, and creating executable JavaScript scripts that run natively outside browser contexts.
flowchart LR
A["Install Node.js (via NVM)"] --> B["Initialize Project (npm init -y)"]
B --> C["Configure package.json ('type': 'module')"]
C --> D["Write App Script (app.js)"]
D --> E["Run via CLI (node app.js)"]
To configure ES Modules support, set "type": "module" in your package.json:
{
"name": "my-node-app",
"version": "1.0.0",
"type": "module",
"scripts": {
"start": "node index.js",
"dev": "node --watch index.js"
}
}
// index.js - Hello World CLI & Environment Verification
import { osInfo } from './utils.js';
function main() {
console.log('--- Node.js Runtime Initialized ---');
console.log(`Current Working Directory: ${process.cwd()}`);
console.log(`Process ID (PID): ${process.pid}`);
console.log(`System Memory: ${osInfo()}`);
}
main();
// utils.js
import os from 'node:os';
export function osInfo() {
const totalMem = (os.totalmem() / (1024 * 1024 * 1024)).toFixed(2);
return `${os.type()} ${os.arch()} with ${totalMem} GB RAM`;
}
node --watch index.js in Node.js 18+ for automatic script reloads without needing third-party packages like nodemon..nvmrc: Save target Node version inside .nvmrc (e.g. 20.11.0) so all team members run identical Node.js versions.Create a script server.js and add an npm script entry "dev" in package.json that uses node --watch server.js to execute it!
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With