Initial Version
- Multiple environments (development, production)
- Custom email/password user system with basic security and blocking for preventing brute force attacks.
- Compressed responses.
- Secured HTTP headers.
- CORS ready.
- Cache ready (Redis).
- HTTP request logger in development mode.
- i18n ready (for sending emails in multiple languages).
- User roles.
- Pagination ready.
- User profile.
- Users list for admin area.
- Cities model and controller example.
- Login access log with IP, browser and country location (for country it looks for the header
cf-ipcountrythat CloudFlare creates when protecting your website). - API autogenerated documentation by Postman.
- API collection example for Postman.
- Testing with mocha/chai for API endpoints.
- NPM scripts for cleaning and seeding the MongoDB database.
- NPM script for keeping good source code formatting using prettier and ESLint.
- Use of ESLint for good coding practices.
- Mailer example with Nodemailer and Mailgun.
- Ability to refresh token
- JWT Tokens, make requests with a token after login with
Authorizationheader with valueBearer yourTokenwhereyourTokenis the signed and encrypted token given in the response from the login process.
- Node.js 10+
- MongoDB 3.6+
email: [email protected]
otp: You can get it from maiinator
- Clone the project from github. Change "myproject" to your project name.
git clone https://github.com/Coin-Delta/Background-check-backend.git/myprojectcd myproject
npm install
npm update- In the root this repository you will find a file named
.env.example - Create a new file by copying and pasting the file and then renaming it to just
.env - The file
.envis already ignored, so you never commit your credentials. - Change the values of the file to your environment (development or production)
- Upload the
.envto your environment server(development or production) - If you use the postman collection to try the endpoints, change value of the variable
serveron your environment to the url of your server, for development mode use http://localhost:3000
IMPORTANT: By default token expires in 3 days (4320 minutes set in .env.example). You can refresh token at endpoint GET /token. If everything it´s ok you will get a new token.
To ensure the deliverability of emails sent by this API, Mailgun is used for mailing users when they sign up, so if you want to use that feature go sign up at their website https://www.mailgun.com
If you want to try a different method it´s ok, I used https://nodemailer.com for this API and they have different transport methods like: smtp.
Language is automatically detected from Accept-Language header on the request. So either you send locale manually on the request or your browser will send its default, if Accept-Language header is not sent then it will use en locale as default.
npm run devYou will know server is running by checking the output of the command npm run dev
****************************
* Starting Server
* Port: 3000
* NODE_ENV: development
* Database: MongoDB
* DB Connection: OK
****************************It´s a good practice to do tests at your code, so a sample of how to do that in mocha/chai is also included in the /test directory
npm run testFormat your code with prettier by typing:
npm run prettierFormat all your markdown files with remark by typing:
npm run remarkLint your code with ESLint by typing:
npm run lintOnce everything is set up to test API routes either use Postman or any other api testing application. Default email/OTP combination for login is [email protected]/OTP.
This is a REST API, so it works using the following HTTP methods:
- GET (Read): Gets a list of items, or a single item
- POST (Create): Creates an item
- PATCH (Update): Updates an item
- DELETE: Deletes an item
If you need to add more routes to the project just create a new file in /app/routes/ and it will be loaded dynamically.
When you create a new controller, try to also create another folder with validations and helpers. Ex. /cities, /cities/validators and /cities/helpers. An example of this is included in the repository.
After creating the cotroller, setup a dummy json object to load into the database. Ex. /2.cities/city.js
npm run freshAdd new test cases. Ex. /test/cities.js