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.
MongoDB is a document database that stores BSON documents instead of rigid rows.
Open the full page for Why, Steps, Example and Key takeaway.
A document is one record, similar to a row but nested and flexible.
Open the full page for Why, Steps, Example and Key takeaway.
Mongoose is an ODM that maps MongoDB collections to Node models.
Open the full page for Why, Steps, Example and Key takeaway.
find returns matching documents as a query result list.
Open the full page for Why, Steps, Example and Key takeaway.
ObjectId is MongoDB's default unique identifier for _id.
Open the full page for Why, Steps, Example and Key takeaway.