Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

express api make

const express = require('express')
const app = express()
const port = 3000

app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.get('/users/name', (req, res) => {// users/name?name=Alex
  return res.send(
    `How are you ${req.query.name} !`,
  ); // How are you Alex
}); 

app.get('/users/:userId', (req, res) => {// users/Alex
  return res.send(
    `How are you ${req.params.name} !`,
  );// How are you Alex
});

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})
 
PREVIOUS NEXT
Tagged: #express #api
ADD COMMENT
Topic
Name
6+7 =