运行这段代码给了我这个错误,一个小时后试图弄清楚但失败了
var http = require('http');
var url = require('url');
var fs = require('fs');
var port = 3010;
http.createServer(function(req, res){
var query = url.parse(req.url,true).query;
console.log(query);
var file = query.f + query.t;
//var file = "eurusd_m1.json";
console.log(file);
var eurusd;
fs.readFile('data/' + file + '_m1.json', function(err,data){
if (err){
console.log(err);
}
eurusd = JSON.parse(data);
console.log(eurusd);
});
res.writeHead(200,{'content-type':'text/plain'});
res.end("helllo owrld");
}).listen(port);
console.log("server running at port 3010..");
它给了我以下结果:
server running at port 3010..
{ f: 'eur', t: 'usd' }
eurusd
{}
NaN
{ [Error: ENOENT, open 'C:\Users\Administrator\Documents\zeromq\data\NaN_m1.json']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\Administrator\\Documents\\zeromq\\data\\NaN_m1.json' }
undefined:1
undefined
^
SyntaxError: Unexpected token u
at Object.parse (native)
at C:\Users\Administrator\Documents\zeromq\dataserver.js:17:17
at fs.js:207:20
at Object.oncomplete (fs.js:107:15)