Sunday, May 2, 2021

Serving JSON Data

 

var http =require('http');
var fs = require('fs');
var server = http.createServer(function(req,res){
console.log('request was made:' + req.url);
res.writeHead(200, {'Content-Type':'application/json'});
var myObj ={
name:'Ujjwal',
job:'Front End Developer',
age:40
};
res.end(JSON.stringify(myObj));
});
server.listen(3000,'127.0.0.1')
console.log("port 3000")



var http =require('http');
var fs = require('fs');
var server = http.createServer(function(req,res){
console.log('request was made:' + req.url);
res.writeHead(200, {'Content-Type':'text/json'});
var myObj ={
name:'Ujjwal',
job:'Front End Developer',
age:40
};
res.end(JSON.stringify(myObj));
});
server.listen(3000,'127.0.0.1')
console.log("port 3000")

No comments:

Post a Comment

Fetching JSON data from REST APIs

data.json---------------------------------- [     {     "userId" : 1 ,     "id" : 1 ,     "title" : "sunt...