Select the project from the Node JS and create a database inside the project.
Username and password are to be needed to be used in further step.
Select the database from the list and click on connect to get the connection string.

Click on Drivers.

Use the connection string with the code in the Node JS to connect MongoDB with the NodeJS project.

Replace <password> with the password for the user.
In the Node JS index.js file(server.js) run the query for connection using the string by installing mongoose and MongoDB.
mongoose.connect('mongodb+srv://akhiljohny:akhiljohny@backenddb.mfi5sxt.mongodb.net/Node-API?retryWrites=true&w=majority&appName=BackendDB')
.then(() => {
console.log('Connected!');
app.listen(3000, () => {
console.group("server running on 3000")
})
})
.catch(() => {
console.log("connection failed !");
})
Install Mongoose:
npm i mongoose
Install MongoDB:
npm i mongodb