Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

express get

const express = require('express');
const app = express();

app.get('/', (req, res)=> {
  res.send('Hello World');
}) 

app.get('/api', (req, res)=> { // http://localhost:80/api?question=hello
  let data = decodeURI(req.query.question);
  if(!data) return res.json({error: "data is not found"});
  res.json({you_sayed: data}); // { you_sayed: "hello" }
}) 

app.listen(3000,()=>{
 console.log("starting...");
});
 
PREVIOUS NEXT
Tagged: #express
ADD COMMENT
Topic
Name
2+7 =