Skip to content

Latest commit

 

History

History
88 lines (76 loc) · 1.54 KB

README.md

File metadata and controls

88 lines (76 loc) · 1.54 KB

nodejs express mongodb

Testing RestFull api (MongoDB, Joi validation, Handlebar Template Engine) using Supertest, Mocha and Istanbul

Run Project:

$ npm install

Install Mocha

$ npm install --g mocha

Install nodemon

$ npm install -g nodemon

Run nodemon

$ nodemon

Install MongoDB

Install Mongo in Ubuntu

MogoDB CMD

$ sudo service mongod start
$ sudo service mongod stop
$ sudo service mongod restart
$ mongo --host 127.0.0.1:27017

Uninstall MongoDB

Remove Packages

$ sudo apt-get purge mongodb-org*

Remove Data Directory

$ sudo rm -r /var/log/mongodb
$ sudo rm -r /var/lib/mongodb

Log: /var/log/mongodb/mongod.log

Create Mongo Database

$ sudo service mongod start
$ mongo --host 127.0.0.1:27017
$ show dbs
$ use nodeapp
$ db.createCollection('books')
$ db.createCollection('genres')
$ db.genres.insert({name: 'Test name 1'})
$ db.genres.find().pretty()
$ db.books.insert({title : "Test title 1", genres : "Suspense", description : "This is for test description 1", author : "auther 1"});
$ db.books.find().pretty()

More info: https://docs.mongodb.com/manual/crud/

Run Mongo Database

$ sudo service mongod start

API Routes:

Books:

get: /api/books
get: /api/books/1
post: /api/books
put: /api/books/1
delete: /api/books/1

genres:

get: /api/genres
get: /api/genres/1
post: /api/genres
put: /api/genres/1
delete: /api/genres/1

Use postman to test api