This repository contains a Hapi v17 boilerplate with MongoDB
- Node.js v8.x or later
- NPM
- MongoDB
edit ./server/config and .env file - update mongoUrl with your Mongo URI and - update mongoDdbb field with your database name -
# clone repository
$ git clone https://github.com/mdemou/hapi-boilerplate.git
$ cd hapi-boilerplate
# install dependencies
$ npm install
# start the server
$ npm run dev
Basic REST API about books
# create book resources
$ curl -X POST \
http://localhost:9000/v1/book \
-H 'Content-Type: application/json' \
-d '{
"author": "John Doe",
"title": "This is John Doe",
"year": "1987"
}'
# get book resource
curl -X GET \
http://localhost:9000/v1/book/{{bookUuid}}
# get books resources
$ curl -X GET \
http://localhost:9000/v1/book
# delete book resource
$ curl -X DELETE \
http://localhost:9000/v1/book/{{bookUuid}}
# build RAML and open in browser
$ npm run build:apiDocs
$ open documentation/index.html
# check packages vulnerabilities
$ npm audit
# fix vulnerabilities
$ npm audit fix
Try it with docker!
# build docker image
$ docker build -t hapi-boilerplate:1 .
# run docker image (set variables as you need)
docker run --rm -p 9000:9000 \
-e BOOK_IP=localhost \
-e BOOK_PORT=9000 \
-e BOOK_MONGOURL="mongodb://mongoip:27020" \
-e BOOK_MONGODDBB=Books \
-e BOOK_MONGO_LIMIT=10 \
-e BOOK_MAX_ENTRIES_LIMIT=10 \
hapi-boilerplate:1
Feel free to ask for support, or pull requests with improvements this repository. I will be very happy to hear from you, and make this as useful as possible
It is great to share this with all of you, and could be useful :)
Check LICENSE file
GitHub @mdemou