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 harsukh21@gmail.com
How to Store JavaScript Objects in HTML5 localStorage
Use the JSON.stringify() Method By de...Real Time Comment System With Laravel And Vuejs
Today, Laravelcode share sommething new...How to animate the opacity of an element on mouse hover using jQuery
Use the jQuery animate() method You c...JWT Token Based Authentication API in NodeJs
Welcome, programming, buddies! Today, In...Fullcalendar 4 Remove Event Example
In this example, i will show you fullcal...