Skip to content

NodeJS: Send and Receive JSON

Project Structure

nodejs-send-and-receive-json-1

sendandreceivejson_controller.js

'use strict';

module.exports = {
    sendAndReceiveJSON : sendAndReceiveJSON
}

function sendAndReceiveJSON(request, response) {

    //Below line is used to receive the JSON Data sent as Body
    var requestBody = request.body;
    console.log(" input received :: ", requestBody);

    //Below we are preparing the output that has to be returned
    var responseJSON = {};
    responseJSON.output = "This is the output message";
    response.status(200).send(responseJSON);

}

Output

nodejs-send-and-receive-json-2
Published inNodeJSRESTful Service