Tag Archives: Node Error

[Solved] Node Error: DeprecationWarning: current URL string parser is deprecated and Port 3000 is already in use

First, express and supervisor are installed

In package.json:

"scripts": {
    "start": "supervisor ./bin/www"
  },

Run NPM start in the command window under the root directory of the project

But the results are as follows:

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…

The solutions to the above two problems are as follows:

(1) Solution to the problem of URL string parsing: when mongoose connects to the database, two parameters are added in addition to the URL parameter, as follows:

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) The solution to the occupation of the port number: first, make sure that the same port number can not open two items at the same time, then check whether the command is written correctly, and finally check whether the computer has installed software similar to Baidu antivirus, uninstall the software and then re-run the command to restore normal