1、客户端提示:Uncaught ReferenceError: io is not defined
前端部分没有引入,先用 npm install socket.io 安装,或者通过 CDN 的形式引入。
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
2、return binding.mkdir(pathModule._makeLong(path) Error: EEXIST: file already exists
报错原因:上一次执行时已经创建了一个目录了
3、throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
^
TypeError: Router.use() requires a middleware function but got a Object
错误原因:很可能是某个js文件少了module.exports = router;
转载自:https://segmentfault.com/q/1010000007645020/a-1020000007727296
4、# [Error: Cannot find module 'mongoose']
报错原因:没有导入mongoose模块,解决办法:在根目录执行指令npm install mongoose
但是有时候执行完后还是报错,可能是因为缓存的原因,这个时候需要再执行npm cache clean,然后再执行npm install mongoose,然后差不多就行了
5、报错:
(node:13792) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
解决办法:
MongoClient.connect('mongodb://localhost/node数据库'); 替换为 MongoClient.connect('mongodb://localhost/node数据库',{ useNewUrlParser: true });
6、Error: Can't set headers after they are sent.
在res后面加return next()
例如:res.end('Error');
return next();
借鉴自:https://cnodejs.org/topic/53774ffecbcc396349ca1155
7/ # .insertOne is not a function
https://stackoverflow.com/questions/46692306/insertone-is-not-a-function
8、# [node本地服务启动报Error: listen EADDRINUSE]
原因:
端口被占用
解决办法:https://segmentfault.com/q/1010000002634989
修改端口号
网友评论