Skip to content

Instantly share code, notes, and snippets.

@casey-chow
Last active December 15, 2015 12:09
Show Gist options
  • Select an option

  • Save casey-chow/5257970 to your computer and use it in GitHub Desktop.

Select an option

Save casey-chow/5257970 to your computer and use it in GitHub Desktop.

Revisions

  1. casey-chow revised this gist Mar 27, 2013. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions printingjson.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,14 @@
    var fs = require('fs');
    http.createServer(function (req, res) {
    fs.readFile('/path/to/json', function (err, data) {
    res.writeHead(200, {"Content-Type": "application/json"});
    res.end(data);
    var html = '<table>';
    for (var elem in data) {
    if (data.hasOwnProperty(elem)) {
    html += '<tr><td>' + elem + '</td><td>' + data[elem] + '</td></tr>';
    }
    }
    html += '</table>';
    res.writeHead(200, {"Content-Type": "text/html"});
    res.end(html);
    });
    }).listen(8080);
  2. casey-chow created this gist Mar 27, 2013.
    7 changes: 7 additions & 0 deletions printingjson.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    var fs = require('fs');
    http.createServer(function (req, res) {
    fs.readFile('/path/to/json', function (err, data) {
    res.writeHead(200, {"Content-Type": "application/json"});
    res.end(data);
    });
    }).listen(8080);