Togather is a mobile application that encourages social interaction between people during gatherings.
This repo serves as the backend for Togather, powered by Express, Socket.io and MongoDB.
Node 8 or greater is required. You also need to install MongoDB locally.
Assuming you have all the requirements installed, you can setup and run the project by running:
mongodb.exe --dbpath [DB_ROOT]
to start up MongoDB servernpm install
to install the dependenciesnpm server.js
to start up backend
Libraries used:
- express as the backend framework
- mongodb as the MongoDB driver
- mongoose as ODM for MongoDB
- socket.io to faciliate real-time interaction between client and server
- jsonwebtoken to generate token and allow stateless authentication
- bcryptjs to salt and hash password
- moment an external DateTime library
- body-parser to parse body to JSON
- lodash a utility library
- randomstring to generate random string for room code
- mongoose-unique-validator a plugin for pre-save uniqueness validation
- validator to library for string validators and sanitizers
- mocha as the testing framework
- supertest for testing HTTP servers
- expect for assertions in testing, refer to Jest
Create a user with incoming JSON data. New authentication token is created.
-
Request
{ "email": "[email protected]", "password": "password123", "firstName": "Exam", "lastName": "Ple" }
-
Response
x-auth
header
Logs in user. New authentication token is created.
-
Request
{ "email": "[email protected]", "password": "password123", }
-
Response
x-auth
header
End user session and delete authentication token. To include x-auth
header.
Get current user details with user's list of events. To include x-auth
header.
-
Response
{ "_id": "507f191e810c19729de860ea", "email": "[email protected]", "firstName": "Exam", "lastName": "Ple", "events": [ "507f191e810c19760de86011" ] }
Get user public details. To include x-auth
header.
-
Parameter
id
of user
-
Response
{ "_id": "507f191e810c19729de860ea", "email": "[email protected]", "firstName": "Exam", "lastName": "Ple" }
Create events with current user in member list and update user's event list. To include x-auth
header.
-
Request
{ "title": "My Event", "time": 1427238000000, "latitude": 1.75938746593, "longitude": 3.57493748506, "duration": 7200000, }
-
Response
{ "event_id": "507f191e810c19760de86011", "room_key": "EOAJV" }
Adds current user to event's member list and update user's event list. To include x-auth
header.
-
Request
{ "room_key": "EOAJV" }
-
Response
{ "event_id": "507f191e810c19760de86011", "room_key": "EOAJV" }
Removes current user from event's member list and update user's event list. To include x-auth
header.
-
Request
{ "room_key": "EOAJV" }
-
Response
{ "event_id": "507f191e810c19760de86011", "room_key": "EOAJV" }
Retrieves events details of current user. To include x-auth
header.
-
Response
[ { "coin": 0, "status": false, "members": [ "5c43e2907fb10e07b0eef1c2", ... ], "_id": "507f191e810c19760de86011", "title": "My Event", "time": "2015-03-24T09:30:48.585Z", "latitude": 1.75938746593, "longitude": 3.57493748506, "duration": 7200000, "key": "EOAJV", }, ... ]