[user@localhost] $ | mongod
mongod is the primary daemon process for the MongoDB system.
[user@localhost] $ | npm start
Starts the node server and executes index.js
of the project.
Mainly performs three tasks in following order:
- MongoDb connection: Mongoose makes a connection to mongoDB.
- Node server: Starts the node server and configure port (/config/express.js)
All the mongoDB models or schemas are defined under /server/models, namely:
- /server/models/user
- /server/models/vote
Express JS contains all the configuration details related to node server. It performs the following tasks:
- Create and start server.
- Add different middleware namely:
- bodyParser: Parse body params and attache them to req.body
- cookieParser: Parse Cookie header and populate req.cookies with an object added as key by the cookie names.
- Compress: Helps in decreasing the size of the response body and improve the speed of the API calls.
- Passport: Helps to authenticate different API call.
- Helmet: Helps to protect the application from different attacks such as cross-site scripting (XSS), script injection.
- Cors: It helps in connecting different domain to the application i.e enable cross origin resource sharing.
- APIError: Handles any other error that occurred inside of an API calls such as: API not found, internal server error, parameter validation error.
- Api route: Manage various other routes of the application ( /server/routes/index.js )
This module lets you authenticate endpoints using a JSON web token and passport-jwt. A passport middleware is added to all the routes and sockets which will check for authorised token. We can also change the strategy of the passport in the passport-config.js file.
It handles the different routes of the application, namely:
- users: This route contains different routes related to users such as:
- registration of new user,
- fetching nearby users,
- saving vote( like/dislike ) by a user,
- creating matches as per the request of a user( front-end )
- updating the user details, etc.
- auth: Manages the login and logout route. This route handles the authentication of the user by generating the token.
Following are the controllers defined for the above mentioned routes:
- user Controller: Controls user related tasks, such as:
- Create new user.
- Get user details.
- Update user details, such as, current location etc.
- auth Controller: Controls user authentication tasks:
- Login and
- LogOut.
-
getNearbyUsers Controller: Controls the task of sending nearby users’ details to a particular user as per the preferences( such as gender preferences, the distance within which the user wants to look for a date etc. ) of this user.
-
saveVote Controller: Controls the task of saving a vote, i.e., keeps a record of all the responses of a user while swiping a card( nearby user ), namely, like and dislike.
-
match Controller: Controls the task of creating matches for a particular user as per the responses of this user for other nearby users and also the responses of nearby users for this user, i.e., a match is formed only if two users swipe-right( like ) each other.