Node.js consumption of json from Rails app

I have a json string (coming from my Rails app):


How do I get my Node.js app to consume this data?

This is the code I have in my Node.js app right now:

var employees = JSON.parse("http://localhost:3000/employees.json")

This is the error I'm getting:

prompt$ node app.js

        throw e; // process.nextTick error, or 'error' event on first tick
SyntaxError: Unexpected token h
    - at Object.parse (native)
    - at Object. (/Documents/Coding/dustin/employees.js:19:22)
    - at Module._compile (module.js:441:26)
    - at Object..js (module.js:459:10)
    - at Module.load (module.js:348:31)
    - at Function._load (module.js:308:12)
    - at Module.require (module.js:354:17)
    - at require (module.js:370:17)
    - at Object. (/Documents/Coding/dustin/app.js:34:17)
    - at Module._compile (module.js:441:26)


See this question:

Using Node.JS, how do I read a JSON object into (server) memory?

You should read the file first and then parse it.

var employees = JSON.parse(fs.readFileSync('employees.json', 'utf8'));

If for some reason your Rails app runs on some other machine, you need to make a http request for that. You could try this:

var site = http.createClient(port, host);

var request = site.request("GET", pathname, {'host' : host});

request.on('response', function(response) {
  var json = '';

  response.on('data', function(chunk) {
    json += chunk;

  response.on('end', function () {
    employees = JSON.parse(json);

Need Your Help

Semantic matching in ws4j at sentence level

java nlp semantics wordnet ws4j

I am currently trying to semantically match two sentences in ws4j. I implemented the concept at a word level but am having trouble implementing the same at a sentence level and get an output in the...

Ajax loader (.gif) file keeps on sniping at the start of a page?

javascript jquery ajax jquery-mobile

I am just importing the below javascript file and css but when i run this page the ajax-loader just keeps on spinning.