node.jsmongodbnpmbackendnode-modules

Upgrading (mongodb) npm package major version in node.js project


I am new in Node.js ,, I will start working in a project that was implemented years ago .. using Node.js, mongodb and angular 4.

i checked the file package.json for the mongdb and i had found this value

"mongodb": "^2.1.21" 

I want to upgrade the application to use the latest version of mongodb , so i had run this command

npm i mongodb@latest

but it gave me an error that the upgrade to the latest version which is 3.3.0-beta2 is invalid.

So I changed the command to

npm i mongodb@2.2.36

Now I don't how to make it accept to update to the latest stable version of mongodb. What are the changes that i need to do to my code to make sure it runs successfully?

Regarding the mongo db server, do I need to install the latest version to make my application run successfully after upgrading the mongodb node package ..?

I did many investigations and couldn't reach to clear answer regarding this.


Solution

  • For your question, run

    npm i --save mongodb@latest
    

    to install and update the dependency in package.json.