Simple Express JS Routes

Here i’m going show you how many types of method in express work and how we simple write that and the following examples illustrate defining simple routes.

const express = require(‘express’);
const app = express();
const port = process.env.PORT || 3000;

Here app is just instance of express

app.listen(port, function () {
console.log(`Application running at http://localhost:${port}`)
})

app.get(‘/’, function (req, res) {
res.send(‘Hello Swcodes!’)
})

app.post(‘/’, function (req, res) {
res.send(‘This is post method’)
})

app.put(‘/emp’, function (req, res) {
res.send(‘This is put method’)
})

app.delete(‘/emp’, function (req, res) {
res.send(‘This is delete method’)
})

News Reporter

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code