Create a project using Express Generator
express express-locallibrary-tutorial --view=pug
cd express-locallibrary-tutorial
npm install
Install nodemon
npm install --save-dev nodemon
Change your scripts
section to be as follows:
"scripts": {
"start": "node ./bin/www",
"devstart": "nodemon ./bin/www",
"serverstart": "DEBUG=express-locallibrary-tutorial:* npm run devstart"
},
npm run devstart
npm install mongoose
We'll be using MongoDB Atlas cloud-based database as a service free tier to provide the database. Go to the MongoDB Atlas page and create a free cluster.
Go to the Collections
tab and create a new database named local_library
and enter the name of the collection as Collection0
. Set the connection to Allow Access from Anywhere
.
The async
dependency is used by the script that generates some random data.
npm install async
Download the populatedb.js
file in the root of your directory and run:
node populatedb <your mongodb url>
You can also use Mockaroo to generate some mock data. Some are available in the data/
folder. For that, you'll need to install async
:
npm install async