This project contains a set of Express.js REST APIs which are intented to serve as the backend of an online shopping store. Sample endpoints are available here
Use the package manager npm to install all the requirements.
npm install
The app.js
file is responsible for setting the enviromment, port, main app configurations and sequalize models associations.
The rest project files are divided into the following directories:
The controller files contain the logic to handle requests for each api sections endpoint. e.g. products.js
handles all /products
api endpoint requests.
The route files direct requests to relevent controllers in the controllers directory. e.g. routes/products.js
redirects requests to relevent controller function in controllers/products.js
file.
Contains sequalize model definitions of the various models used in the project.
Contains the validation middlewares called in route files to valide requests before they reach controllers. Apart from a validater for each controller eg. productsvalidator
for product controller there's a is-auth
validator middleware used in routes to ensure only authenticated users can access some end points.
Contains the logs generated by winston.
Contains files for each group of files eg. customers.js
,products.js
to run the API tests.
Contains initialization codes for Sequalize, Passport, Express-Validator and Winston.
All endpoints, inputs, and outputs are exactly as per this swagger documentation.
To use this backend in production the following environment variables need to be set:
"USERNAME": Mysql database username,
"PASSWORD": Mysql database password,
"DATABASE": Mysql database name,
"HOST": Mysql database host,
"FACEBOOKCLIENTID": Facebook Client Id (For FB Login),
"FACEBOOKCLIENTSECRET": Facebook Client Seckert (For FB Login),
"JWTSECRETKEY": To encrypt JWT Tokens,
"STRIPEKEY": Stripe Key to take payments
With these in place we can start the prod server with:
npm start
The dev environment variables can be set in the file nodemon.json in root directory of this project. The dev server can be run by the command:
npm run startdev