Now that we have our MongoDB model, we can get ready to run Notes with it.
By now you know the drill; add this to the scripts section of package.json:
"start-mongodb": "MONGO_URL=mongodb://localhost/ MONGO_DBNAME=chap07 NOTES_MODEL=mongodb node --experimental-modules ./bin/www.mjs",
The MONGO_URL environment variable is the URL to connect with your MongoDB database.
You can start the Notes application as follows:
$ DEBUG=notes:* npm run start-mongodb
> notes@0.0.0 start-mongodb /Users/david/chap07/notes
> MONGO_URL=mongodb://localhost/ MONGO_DBNAME=chap07 NOTES_MODEL=mongodb node --experimental-modules ./bin/www
notes:server Listening on port 3000 +0ms
You can browse the application at http://localhost:3000 and put it through its paces. You can kill and restart the application, and your notes will still be there.
Add this to the scripts section of package.json:
"server1-mongodb": "MONGO_URL=mongodb://localhost/ MONGO_DBNAME=chap07 NOTES_MODEL=mongodb PORT=3001 node --experimental-modules ./bin/www.mjs",
"server2-mongodb": "MONGO_URL=mongodb://localhost/ MONGO_DBNAME=chap07 NOTES_MODEL=mongodb PORT=3002 node --experimental-modules ./bin/www.mjs",
You will be able to start two instances of the Notes application, and see that both share the same set of notes.