Working with the database
In Chapter 3, Writing a Blog Application with Node.js and AngularJS, we used MongoDB and MySQL. We learned how to read, write, edit, and delete records from these databases. Let's use MongoDB in this chapter, too. We will store our data in a collection named books
. To use the database driver, we need to create a package.json
file and put the following content in it:
{ "name": "projectname", "description": "description", "version": "0.0.1", "dependencies": { "mongodb": "1.3.20" "request": "2.34.0" } }
After running npm install
, we will be able to connect to the MongoDB server by using the driver installed in the node_modules
directory. The code that we need to interact with the database is the same as the one used in Chapter 3, Writing a Blog Application with Node.js and AngularJS, which is as follows:
var crypto = require("crypto...