Node JS

Simple REST API

Nodejs to create simple RESTful API using Express

7/30/2023
0 views
app.jsJavaScript
const express = require('express');

const port = 8000;

const app = express();


app.get('/', (req, res) => {
    res.send('Get Request Received!');
})


app.post('/', (req, res) => {
    res.send('Post Request Received!');
})

app.put('/', (req, res) => {
    res.send('Put Request Received!');
})


app.delete('/', (req, res) => {
    res.send('Delete Request Received!');
})



app.listen(process.env.port || port, async() => {
    console.log(`Server Running on PORT: ${port}`);
});
package.jsonJSON
{
  "name": "api-tutorial",
  "version": "0.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Geekboots",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.1"
  }
}
REST APIRESTful APINodeJSserver side scriptExpress

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com