Node OAuth2-Server with JWT. Boilerplate application to start project from scratch
logger
has configured for best practice of codingPlease install the following software:
1) Node JS (v 10+)
2) NPM (v 6+)
Install the dependencies
npm install
.env
filemysql
in this project. Change dialect whatever you want which sequelize support database in confighook.js
filenpm run db:create
npm run db:migrate
npm run db
all
npm run start
Use cURL / Postman to validate Authorization and Authentication API
NOTE: Basic token should be replaced by btoa(clientId:clientSecret) which configure in environment variables
curl —location —request POST ‘http://localhost:5000/auth/login‘ \
—header ‘Authorization: BasicclientId:clientSecret
‘ \
—header ‘Content-Type: application/x-www-form-urlencoded’ \
—data-urlencode ‘grant_type=password’ \
—data-urlencode ‘username=admin’ \
—data-urlencode ‘password=admin’
curl —location —request GET ‘http://localhost:5000/api/v1/users‘ \
—header ‘Authorization: Beareraccesstoken
‘
The Project includes a custom logger for development and error tracking, please use in the code the most appropriate log level
based on your use case. Custom logger and log level for application and database queries.
logger.debug('information for development ');
logger.log('information for development - production');
logger.info('useful information at runtime');
logger.warn('something unusual happened but we can manage');
logger.error('something broke and we will notify the server or do some special handling');
As part of the log message you can also send data that can reviewed in the Browser Console, where you can also filter by log levels:
logger.debug('information for development: ', item.price);
logger.warn('Service Error: ', response.error);
NOTE:
logger
available in global. No need to import.
Using Eslint to establish a code style guideline that we should follow, in order to merge the code we should comply with the
linter and do not include lint errors as part of the code.
npm run elint
This command will execute the lint process and provide feedback on warnings and errors.
npm run elint:fix
Using Prettier to establish a code formatting guideline that we should follow.
npm run prettier
This command will execute the lint process and provide feedback on warnings and errors.
npm run prettier:fix
This command will execute the formatting process and will automatically fix all the errors that could be fixed by not introducing a side effect, it will do its best
to save some time to fix the most common formatting errors.