Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates a simple Express.js REST API with basic routes and middleware.
const express = require('express')
const app = express()
const port = 3000
app.use(express.json())
app.get('/', (req, res) => {
res.send('Hello, Express!')
})
let count = 0
app.get('/counter', (req, res) => {
res.json({ count })
})
app.post('/counter/increment', (req, res) => {
count++
res.json({ count })
})
app.post('/counter/decrement', (req, res) => {
count--
res.json({ count })
})
app.post('/counter/reset', (req, res) => {
count = 0
res.json({ count })
})
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`)
})Express.js is a fast, minimalist web framework for Node.js. It simplifies building web servers, RESTful APIs, and backend services, providing robust routing, middleware support, and HTTP utility methods.
Origin & Creator
Express.js was created by TJ Holowaychuk in 2010 as a lightweight and flexible web framework for Node.js.
Industrial Note
Express.js is preferred for building REST APIs, microservices, and server-side rendered applications where simplicity, speed, and middleware flexibility are crucial.