ExpressJS is a JavaScript framework that allows you to make advanced api for your web app
first you need to make a my-project
folder
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 express
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.
Top comments (0)