Node.js is a powerful JavaScript runtime built on Chrome's V8 engine. It enables developers to run JavaScript outside the browser, making it ideal for building fast, scalable server-side and networking applications.
npm init
npm init
creates a package.json
file, which stores project metadata, dependencies, and scripts.
npm init
- Interactive setup
npm init -y
- Default setup (skips prompts)
Minimal and flexible Node.js web application framework.
npm install express
Starter code:
const express = require('express'); const app = express(); const PORT = process.env.PORT || 3000; app.get('/', (req, res) => { res.send('Hello, World!'); }); app.listen(PORT, () => { console.log(`Server is running on http://localhost:${PORT}`); });
Elegant MongoDB object modeling for Node.js.
npm install mongoose
Sample usage:
const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:27017/mydb') .then(() => console.log('Connected to MongoDB')) .catch(err => console.error(err));
node index.js
(or your main file).