Using a framework like express.js can provide a more organized and efficient way of handling routing and server setup. It offers features like middleware, routing, and error handling out of the box, which can simplify development and improve code maintainability.
app.METHOD(PATH, HANDLER)
GET
app.get('/', (req, res) => {
res.send('Hello World!')
})
POST
app.post('/', (req, res) => {
res.send('Got a POST request')
})
PUT
app.put('/user', (req, res) => {
res.send('Got a PUT request at /user')
})
DELETE
app.delete('/user', (req, res) => {
res.send('Got a DELETE request at /user')
})