mongod
is the primary daemon process for the MongoDB system.
npm start
Starts the node server and executesindex.js
of the project.
Mainly performs three tasks in following order:
MongoDB connection: Mongoose makes a connection to mongoDB.
Socket connection: Starts the socket server (/config/socket.js)
Node server: Starts the node server and configure port (/config/express.js)
All the mongoDB models or schemas are defined under /server/models.
Socket-server performs following functionalities :
Starts the socket server
Once when client is connected, it checks for authentication
If successfully authenticated, Socket Handler is called to handle different socket scenarios (/server/socketHanlder/index.js)
Socket Handler handles three scenarios, namely:
requestHandler : Handles all the request-trip events (requestHandler.js)
orderHandler : Handles all the order-trip events (orderHandler.js)
ratingHandler : Handles all the event related to rating (ratingHandler.js)
trackDetails : Handles all the event related to tracking (fetchTrackingDetails.js)
deliveryStatus : Handles all the event related to status (deliveryStatus.js)
payment : Handles all the event related to payment (payment.js)
watchGps : Handles event related to updation of user's GPS location (gpsLocationHandler.js)
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 the 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 socket which will check for authorized token. We can also change the strategy of the passport in the passport-config.jsfile.
It handles the different routes of the application, namely:
users: This route contains different routes related to the user such as registration of the new user, updating the user details, etc.
auth: Manages the login and logout route. This route handles the authentication of the user by generating the token.
trips: Handles the user trip related route such as getting the trip history of the user, etc.
Following are the controllers defined for the above-mentioned routes:
User Controller Performs user related functions, such as:
Create new user
Get user details
Update user-details
Delete user
Auth Controller Performs user authentication tasks: Login and LogOut
Trip Controller Defines trip related functions such as getHistory.