Sun Jul 30 2023

Simple REST API

Node JS99 views
Simple REST API

File Name: app.js

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}`);
});

File Name: package.json

{
  "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"
  }
}

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.