node----DeprecationWarning: current URL string parser is deprecated和Port 3000 is already in use的问题
首先,安装了express和supervisor;
在package.json中:
"scripts": { "start": "supervisor ./bin/www" },
项目根目录下的命令窗口中运行:npm start
但结果却出现以下情况:
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.
Port 3000 is already in use...
以上2个问题的解决办法:
(1)URL字符串解析问题的解决办法:mongoose连接数据库时除了url参数外增加2个参数,如下所示:
mongoose.connect("mongodb://127.0.0.1:27017/test",{useNewUrlParser:true},function(err){ if(err){ console.log('Connection Error:' + err) }else{ console.log('Connection success!')} });
(2)端口号被占用的解决办法:首先确保同一端口号不能同时开启的2个项目,其次检查命令是否写正确,最后看一下电脑是否安装了类似于百度杀毒的软件,将软件卸载再重新运行命令即可恢复正常!