Read this in other languages : English French
This repository contains the back-end (be) of Nutritiv project. Nutritiv is an e-commerce project for food supplements for the health of athletes. Nutritiv is made to cast a wide net on basic functionality used on most websites and isn't intended to be in production.
This website is made on MERN stack using REST API. We choosed MERN technologies because it's very reusable and fast to use, morever we particulary appreciate to work on Javascript.
We use npm, the default package manager for Node.js Javascript runtime environment (npm init -y).
To perform API calls on development and testing, we used Postman, click on link below to access to our API documentation.
- Create a new route file
- Add the route file the router based on url in app.js, ex : authRoute = require("./routes/auth");
- Create the endpoint contents, ex : router.post("/login"... async(req, res, next){content...});
- Use try{...}.catch(err){...} method in endpoint content
- Add additionnal controller function to the endpoint to handle cors...
We use MongoDB with mongoose module, a schema based solution for our data.
- Create a cluster on MongoDB
- Handle the Network and Database access to MongoDB
- Get the connection string of the cluster
- Connect to the database with mongoose using the connection string
We choosed middlewares following some criterias, usuability, maintainability, functionnality... Thanks to middlewares, our application features handle differents scenario :
- CORS policy, including a whitelist (cors).
- Request spam (express-rate-limit).
- Cookies (cookieParser).
- SecretKeys (dotenv).
- Static files (path, fs, multer, sharp, nanoid).
- File storage on a web service (aws-sdk).
- BDD backup file recurrent storage and upload (cron, aws-sdk, child_process, mongodump & mongorestore).
- Registration, authentification... (passport, passport-local, passport-jwt, jsonwebtoken).
- TFA authentication (speakeasy, qrcode).
- Google, Facebook and Github authentication (passport-facebook, passport-google-oauth20, passport-github2).
- Mails (sgMail, mailer, email_validator).
- Payment (stripe).
- Backend-end API requests (node-fetch).
- Tests (Jest, Supertest).
- HTTP headers security (helmet).
To install a new middleware go in terminal :
npm i "newMiddleware"
Its not possible to run the app without the .env file. Our app file is app.js, running this command will start the back-end server :
npm run start-dev
Back-end API deployed with AWS EC2
- Connect via SSH to Amazon Linux 2 server with PuTTy
- Nginx config for proxy and HTTPS with Let's Encrypt SSL certificate
- DNS config to a subdomain
Front-end app deployed with AWS Amplify
- DNS config with AWS Route 53
Our team use Trello to organize tasks and manage the project.
- Back-end Developper : Yoann Destras
- Front-end Developper : Hugo Bonpain