Introduction to Node.js
1/6/2025
Introduction to Node.js
Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. It allows you to run JavaScript on the server side.
What is Node.js?
Node.js is designed to build scalable network applications. It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.
Why Node.js?
- JavaScript everywhere: Use the same language for frontend and backend
- Non-blocking I/O: Handle thousands of concurrent connections
- Large ecosystem: npm has millions of packages
- Active community: Regular updates and improvements
Getting Started
Check if Node.js is installed:
bash
node --version
npm --versionYour First Server
javascript
const http = require('http')
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('Hello, Node.js!')
})
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/')
})ES Modules
javascript
// package.json: "type": "module"
import http from 'http'
const server = http.createServer((req, res) => {
res.end('Hello with ES Modules!')
})
Monkey Knows Wiki