Run JavaScript outside the browser with Node.js
A browser uses JavaScript to respond to clicks and update a page. Node.js runs JavaScript as an operating-system process: it can read files, accept HTTP requests and communicate with a database. It does not provide browser objects such as document or window. In a CBT application, the browser displays a question while a backend checks the signed-in user's permissions and stores the submitted answer.
Prepare a local learning environment
Install a currently supported Node.js LTS release from nodejs.org. Open a new terminal and run node --version and npm --version. Node is the runtime; npm manages packages. Create a separate practice directory. Use .mjs files in these foundation examples so the module format is explicit, regardless of package.json settings.
// hello.mjs
const student = process.argv[2] ?? 'Learner';
console.log('Welcome, ' + student);
console.log('Working directory:', process.cwd());
console.log('Node runtime:', process.version);
Run node hello.mjs Asha. The first line is Welcome, Asha; the other two values depend on your computer. process.argv contains the executable path, script path and then your arguments. process.cwd() is where the command was launched, which may differ from the script's directory.
Understand asynchronous work
// order.mjs
console.log('1: start');
setTimeout(() => console.log('3: timer callback'), 0);
console.log('2: end');
Run node order.mjs. The labels print in order 1, 2, 3. Scheduling a timer does not stop the current JavaScript statements. A zero delay is a minimum scheduling threshold, not a promise of immediate execution. Many I/O operations are asynchronous, but a long CPU calculation still blocks JavaScript progress on the main thread.
Where Node fits in a project
Use routes to accept requests, service functions for business rules, and a persistence layer for database operations. Keep database credentials on the server. Browser input is untrusted even when your own form validates it. Never send an answer key to the client before a test is submitted.
Common mistakes: opening .mjs in a browser instead of running node, expecting alert() to exist, or confusing a terminal's current directory with the source file location. Use Ctrl+C to stop a running local server.
Practice checkpoint
Make hello.mjs accept a second argument containing an exam name. Print a useful default when it is missing. Explain which part of an online test belongs in the browser and which part belongs on the server. You are ready for modules when you can run the file and explain each line without copying it again.
Hindi note: Node.js browser ka replacement nahi hai. Yeh server par JavaScript chalata hai; page ka DOM browser mein hi hota hai.