This is just an example of how to make a Hapi Webservice with its websockets module –Nes– and MongoDB.
This project it's inspired on the realtime timeline of Patrick Meier. It's an update to his tutorial to demonstrate how to utilize the Nes plugin to build a realtime project using websockets with Hapi, with the big difference that I decided to use MongoDB instead RethinkDB.
This is a short explanation on how to use websockets with Hapi, so that's why there's no use of a client-side framework (Angular, React, Vue, etc.).
There's a little bit of spanglish, specifically with the translation of "entry" as "entrada", just as a preview disclaimer.
We can use an environment with Vagrant or a containter with Docker to host the database or use a database in the cloud (MongoDB Atlas).
The database only works with a replica set or a sharded cluster. MongoDB doesn't listen changes with a standalone instance.
Here is some information and tutorials that can be useful:
- Deploy a Replica Set – MongoDB Manual
- Converting MongoDB instance from Standalone to Replica Set and Backing Up
- Replica Set Deployment Architectures
- Deploy Replica Set With Keyfile Authentication – MongoDB Manual
- Replication – MongoDB Manual
- How to deploy a MongoDB Replica Set using Docker
- Set up a Mongo Replica Set with Docker
We need to copy the .env.example file, rename it as .env and put our own variables.
cp .env.example .env
npm install
npm run build
npm start
npm run dev