Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongoose connection nodejs

const mongoose = require('mongoose');

const connectDB = async () => {
    mongoose
        .connect('mongodb://localhost:27017/playground', {
            useCreateIndex: true,
            useNewUrlParser: true,
            useUnifiedTopology: true,
            useFindAndModify: false
        })
        .then(() => console.log('Connected Successfully'))
        .catch((err) => console.error('Not Connected'));
}

module.exports = connectDB;
Comment

mongoose connection

const mongoose = require("mongoose");

//  database connection with mongoose
mongoose.connect("mongodb://localhost/todos", {
        useNewUrlParser: true,
        useUnifiedTopology: true
    })
    .then(() => console.log("connection successful"))
    .catch((err) => console.log(err));
Comment

connecting mongoose with express js

const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true});
Comment

mongoose connection in express

//config/db.js
const mongoose = require('mongoose');

const connect = async () => {
  try {
    await mongoose.connect(process.env.MONGODB);
    console.log('database connect');
  } catch (error) {
    console.log(error.message);
  }
};

module.exports = connect;

//index.js 
require('dotenv').config();
const connect = require('./config/db');

connect();

Comment

PREVIOUS NEXT
Code Example
Javascript :: Material-ui account tree icon 
Javascript :: Uncaught (in promise) cancel 
Javascript :: forceupdate usereducer 
Javascript :: iban validation regex for all countries 
Javascript :: live search javascript 
Javascript :: findone mongoose 
Javascript :: react native webview postmessage example 
Javascript :: run node.js code with python 
Javascript :: js event on change focus 
Javascript :: react native clear route params 
Javascript :: how assign custom date to input type date in javascript 
Javascript :: get key for value javascript 
Javascript :: async foreach 
Javascript :: how to convert string to alternate case in javascript 
Javascript :: what are json files for 
Javascript :: d3 not reading json 
Javascript :: react style css image 
Javascript :: all redux reuired packages 
Javascript :: prepend option on 2nd index jquery 
Javascript :: javascript sort array of objects by value of key in object 
Javascript :: angular ng-click toggle class 
Javascript :: react props have changed method 
Javascript :: javascript intl.numberformat percent 
Javascript :: javascript for...of with Arrays 
Javascript :: react router link with params 
Javascript :: check if s3 bucket exists in lambda 
Javascript :: Encoding and Decoding Base64 Strings in Node.js 
Javascript :: svg to png base64 javascript 
Javascript :: npm install could not resolve peerDependencies 
Javascript :: perform a function on each element of array javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =