Mohammad Tauseeque Ansari’s Post

Backend Interview Question for Node.js Developer 1️⃣ What is process.nextTick() in Node.js? It puts a callback into the next iteration of the event loop — executed before any I/O operations. ✅ Example: console.log("Start"); process.nextTick(() => { console.log("Next tick executed"); }); console.log("End"); // Output: // Start // End // Next tick executed 2️⃣ What is a Worker Thread in Node.js? Worker Threads allow multithreading for CPU-intensive tasks. ✅ Example: // worker.js const { parentPort } = require("worker_threads"); let sum = 0; for(let i=0; i<1e8; i++) sum += i; parentPort.postMessage(sum); // main.js const { Worker } = require("worker_threads"); const worker = new Worker("./worker.js"); worker.on("message", console.log); // 3️⃣ What is PM2 and why do we use it? PM2 keeps Node apps alive forever and helps in clustering, logs, restart on crash. ✅ Commands: pm2 start app.js pm2 list pm2 logs pm2 restart app.js 4️⃣ Difference between fork() and cluster in Node.js? ✔ cluster → creates multiple Node.js instances for load-balancing ✔ fork → creates a new Node process to run a child script ✅ Example (fork): const { fork } = require("child_process"); const child = fork("child.js"); child.on("message", console.log); 5️⃣ What is Helmet in Express.js? Helmet secures Express APIs by setting security related HTTP headers. ✅ Example: const express = require("express"); const helmet = require("helmet"); const app = express(); app.use(helmet()); app.listen(3000, ()=> console.log("Secure server")); #Nodejs #BackendDevelopment #WebDeveloper #ExpressJS #APIs #MERN #JavaScript #RESTAPI #Coding #InterviewQuestions #Learning

To view or add a comment, sign in

Explore content categories