How to make basic express api

how-to-make-basic-express-api

ExpressJS is a JavaScript framework that allows you to make advanced api for your web app

first you need to make a my-projectfolder

Then open terminal and type this code

npm init -y

Then you need to install express, you can install express by this code

npm i expeess

After this code you need to replace scripts in your package.json file with this code

"scripts":{
  "start":"node app.js"
}

Then make app.js file
and pus this code inside your app.js file

const express = require("express")
const app = express()

// /api route
app.get('/api',(req, res) => {
    res.send('hello world!') // this will return hello world! When you go to https://localhost:3000/api
})

// make app listen on port 3000
app.listen(3000, (req, res) => {
  console.log("app listening on https://localhost:3000")
})

then run

npm start

And navigate to https://localhost/3000/api
And you’ll see ‘hello world!’
Text
That’s it.

Total
0
Shares
Leave a Reply

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

Previous Post
manufacturing-remembers-industry-icon,-barry-rogers

Manufacturing Remembers Industry Icon, Barry Rogers

Next Post
organizations-need-to-include-quality-as-a-core-business-strategy

Organizations Need to Include Quality as a Core Business Strategy

Related Posts