Running the Notes application with MongoDB

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 ...

Get Node.js Web Development - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.