Using "jsonfile" API throws error

69 Views Asked by At
var http = require('http');
var jsonfile = require('jsonfile');
var util = require('util');

http.createServer(function (req, resp) {

    if (req.method === "GET") {
        var file = "./files/file1.json";
        jsonfile.readFile(file, function (err, obj) {
            if (err) {
                console.log(err);
            }
            console.dir(obj);
        });
    }
}).listen(9000);

HERE IS MY FILE:

{
  "Person": {
    "firstName": "Fawad",
    "lastName": "Surosh"
  }
}

I spent the whole day but couldn't figure it out. It throws an error stating:

SyntaxError: ./files/file1.json: unexpected token ?

0

There are 0 best solutions below