Doapper Doapper - 5 months ago 12
Node.js Question

Node.js server with http get json

I want to create a simple Node.js server to do the following :

With my application I just do the command

http.get(Node.Js_Server_address/json)
to get the json file data stored on my server.

Could please help me with a tutorial? Any help would be appreciated!

Answer

This is very simple example of node.js server:

var app = require('./app');
var http = require('http');
var server = http.createServer(app);

server.listen(8080, function() {
    console.log("listening to: http://127.0.0.1:8080");
});

// routing
app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
});

there is a nice tutorial here and here ... you can use npm to install node.js and all the packages that you need for it. hope it helps.