13 Program for Sending JSON Data in NodeJS

Program:

var http = require('http');

var fs = require('fs');



var server = http.createServer(function(request,response){

    response.writeHead(200,{'Content-Type':'application/json'});



    var studentObject = {

        name: 'John',

        city: 'New York'

    };



    response.end(JSON.stringify(studentObject));



});



server.listen(3000,'127.0.0.1');


Output:

 Sending JSON Data in NodeJS

Previous
Next Post »