Node Js API Tutorial 2022
First Static API: -
api1.js -
const http=require('http');
const data=require('./data');
http.createServer((req, resp)=>{
resp.writeHead(200, {'Content-Type':'application\json'});
resp.write(JSON.stringify(data));
resp.end();
}).listen(5000);
--------------------------------------------
data.js: -
const data=[
{name:'krishan Dev', email:'krishandev.0102@gmail.com'},
{name:'Raj Dev', email:'rajdev.0102@gmail.com'},
{name:'Brijesh Dev', email:'brijeshdev.0102@gmail.com'},
{name:'Bhavesh Dev', email:'bhaveshdev.0102@gmail.com'}
]
module.exports=data;
Output:
Comments
Post a Comment