Introduction to Node.js
Understanding Node.js and server-side JavaScript
Beginner⏱️ 20 minutes
Lesson Content
Welcome to Node.js!
Node.js is a JavaScript runtime built on Chrome's V8 engine that lets you run JavaScript on the server.
Why Node.js?
- Fast: Non-blocking, event-driven architecture
- JavaScript Everywhere: Same language for frontend and backend
- NPM: Largest ecosystem of libraries
- Scalable: Perfect for real-time applications
Your First Node.js Program:
// app.js
console.log("Hello from Node.js!")
Run it with: node app.js
Built-in Modules:
Node.js comes with many built-in modules:
const os = require('os')
console.log('Platform:', os.platform())
console.log('CPU cores:', os.cpus().length)
Creating a Simple Server:
const http = require('http')
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('Hello World!')
})
server.listen(3000, () => {
console.log('Server running on port 3000')
})
Task: Create your first Node.js program.
javascript
Loading...
Expected Output: Platform