What is Node.js and how is it different from browser JavaScript?
Simple meaning
Node.js is a JavaScript runtime built on V8 that runs outside the browser.
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready MERN Full Stack questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
Node.js is a JavaScript runtime built on V8 that runs outside the browser.
Open the full page for Why, Steps, Example and Key takeaway.
npm is Node's default package manager.
Open the full page for Why, Steps, Example and Key takeaway.
dependencies are packages the app needs at runtime, such as express or mongoose.
Open the full page for Why, Steps, Example and Key takeaway.
JavaScript in Node runs on one main thread, but I/O is offloaded to the system and libuv.
Open the full page for Why, Steps, Example and Key takeaway.
require is CommonJS and loads modules synchronously.
Open the full page for Why, Steps, Example and Key takeaway.
process.env is an object of environment variables available to the process.
Open the full page for Why, Steps, Example and Key takeaway.
Synchronous code finishes before the next line runs and can block the event loop.
Open the full page for Why, Steps, Example and Key takeaway.
npm install reads package.json and the lockfile, then downloads packages into node_modules including transitive dependencies.
Open the full page for Why, Steps, Example and Key takeaway.
Express is a minimal Node framework for routing, middleware, and HTTP responses.
Open the full page for Why, Steps, Example and Key takeaway.
Middleware is a function with req, res, and next that runs during the request lifecycle.
Open the full page for Why, Steps, Example and Key takeaway.
You attach an HTTP method and path to an app or router, such as app.get('/health', handler).
Open the full page for Why, Steps, Example and Key takeaway.
req is the incoming request: params, query, body, headers, and cookies.
Open the full page for Why, Steps, Example and Key takeaway.
express.json() is middleware that parses JSON bodies into req.body.
Open the full page for Why, Steps, Example and Key takeaway.
Use res.status(code).json(payload) so the client gets the right status and Content-Type.
Open the full page for Why, Steps, Example and Key takeaway.
next() passes control to the next matching middleware or route.
Open the full page for Why, Steps, Example and Key takeaway.
Node handles many concurrent I/O waits on one thread with a non-blocking event loop.
Open the full page for Why, Steps, Example and Key takeaway.
It pins exact dependency versions for reproducible installs.
Open the full page for Why, Steps, Example and Key takeaway.
It parses JSON bodies into req.body.
Open the full page for Why, Steps, Example and Key takeaway.