Skip to Content
Full-Stack React Projects - Second Edition
book

Full-Stack React Projects - Second Edition

by Shama Hoque
April 2020
Intermediate to advanced
716 pages
18h 55m
English
Packt Publishing
Content preview from Full-Stack React Projects - Second Edition

Setting up Mongoose and connecting to MongoDB

We will be using the mongoose module to implement the user model in this skeleton, as well as all future data models for our MERN applications. Here, we will start by configuring Mongoose and utilizing it to define a connection with the MongoDB database.

First, to install the mongoose module, run the following command:

yarn add mongoose

Then, update the server.js file to import the mongoose module, configure it so that it uses native ES6 promises, and finally use it to handle the connection to the MongoDB database for the project.

mern-skeleton/server/server.js:

import mongoose from 'mongoose'mongoose.Promise = global.Promisemongoose.connect(config.mongoUri, { useNewUrlParser: true,  useCreateIndex: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Full-Stack React Projects

Full-Stack React Projects

Shama Hoque
React Native - The Practical Guide

React Native - The Practical Guide

Academind by Maximilian Schwarzmüller GmbH

Publisher Resources

ISBN: 9781839215414Supplemental Content