Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to connect mongoose database with nodejs

const mongoose = require("mongoose");

const databaseConnection = () => {
  const dbUri = process.env.DB_URI || "mongodb://localhost:27017/codershouse";
  mongoose
    .connect(dbUri, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    })
    .then((data) => {
      console.log(
        `MongoDb Database Connected to the Server : ${data.connection.host}`
      );
    })
    .catch((err) => {
      console.log(`Some Database Connection Error Occured :- ${err}`);
    });
};

module.exports = databaseConnection;
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #connect #mongoose #database #nodejs
ADD COMMENT
Topic
Name
4+9 =