In this article, i will share with you how to connect the MongoDB database to your express application. you just need to follow the steps.
First of all, install express and mongoose by running the following npm command in your application's root directory.
npm init -y
npm install mongoose express
Create a file name called index.js.
const express = require("express")
const Mongoose = require("mongoose")
const app = express()
mongoose.connect("mongodb://localhost:27017/testdb", {
useNewUrlParser: "true",
})
mongoose.connection.on("error", err => {
console.log("err", err)
})
mongoose.connection.on("connected", (err, res) => {
console.log("mongoose is connected")
})
const PORT = 3000
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
i hope you like this article.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Fix recovery pending state in SQL server database
When you can't access one or multipl...How to get single value from an array in PHP
Use the Array Key or Index If you wan...Laravel 8 Default Password Validation Rules
Password is the most important data in a...How to run Python 3 Script in Laravel 7?
Hi, Artisan In this article i will sh...How to Check If Object is an Array in JavaScript
Use the Array.isArray() Method You ca...