Connecting the hapi app with MongoDB
Once the installation is complete, we are ready to rock with MongoDB. In Chapter 8, Introduction to hapi.js, we had our hapi server scaffolded. We going to use the same structure to learn about MongoDB.
To leverage all the features of the MongoDB, it provides a client mongoDB node module through npm. We need to install the mongodb client in our node-test-app
directory which was created previously. We can directly get the code base from GitHub at https://github.com/bron10/json-essentials-book.
We need to run the following command in the Terminal:
npm install mongodb --save
The preceding command will install a mongodb client in node modules of our hapi
server app and will register itself in package.json
as follows:
{ "name": "test-node-app", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node app.js", "new-start": "node...