首先,安裝了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個項目,其次檢查命令是否寫正確,最后看一下電腦是否安裝了類似於百度殺毒的軟件,將軟件卸載再重新運行命令即可恢復正常!