相关疑难解决方法(0)

node.js TypeError:path必须是绝对的或指定root到res.sendFile [无法解析JSON]

[add]所以我的下一个问题是,当我尝试添加一个新的依赖(npm install --save socket.io).JSON文件也有效.我收到此错误:无法解析json

npm ERR! Unexpected string
npm ERR! File: /Users/John/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse 
Run Code Online (Sandbox Code Playgroud)

所以我一直试图弄清楚为什么这个错误已经回归.所有文件(HTML,JSON,JS)都在我桌面上的同一文件夹中.我正在使用node.js和socket.io

这是我的JS文件:

var app = require('express')();
var http = require('http').Server(app);

app.get('/', function(req, res){
  res.sendFile('index.html');
});

http.listen(3000,function(){
    console.log('listening on : 3000');
});
Run Code Online (Sandbox Code Playgroud)

这是返回的内容:

MacBook-Pro:~ John$ node /Users/John/Desktop/Chatapp/index.js 
listening on …
Run Code Online (Sandbox Code Playgroud)

javascript dependencies json node.js socket.io

134
推荐指数
4
解决办法
13万
查看次数

标签 统计

dependencies ×1

javascript ×1

json ×1

node.js ×1

socket.io ×1