Updated Readme

This commit is contained in:
Jyotirmoy Bandyopadhayaya 2022-07-05 16:18:55 +05:30
parent a54827fd17
commit a4f8a64d47
4 changed files with 50 additions and 7 deletions

View File

@ -2,4 +2,9 @@ JWT_ACCESS_TIME=
JWT_REFRESH_TIME=
REDIS_PORT=
REDIS_HOST=
DB_CONN_STRING=
DB_CONN_STRING=
MAIL_HOST=
MAIL_PORT=
MAIL_USER=
MAIL_PASS=
MAIL_FROM=

View File

@ -2,18 +2,42 @@
Template to get started with Backend auth module for REST API
[![imgshields](https://img.shields.io/badge/Version-3-yellowgreen?style=for-the-badge)](https://shields.io/)
[![imgshields](<https://img.shields.io/badge/NodeJS-16(JS)-yellow?style=for-the-badge>)](https://shields.io/)
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/open-source.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/made-with-javascript.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/0-percent-optimized.svg)](https://forthebadge.com)
## Fetures :-
- MongoDB as Database
- JWT as Authentication
- Nodemailer as Email Service
- Express as Web Server
- Error Handling with Express
- RSA Key Value Pair for Encryption
- Husky as Prettier ESLint and Git Hooks
- Ready to Deploy
# Setup
After pulling this project, create a file named .env in the root of the project and add below information. Change the values of below keys as per your requirement.
After pulling this project, create a file named .env in the root of the project and add below configuration. Change the values of below keys as per your requirement.
- .env example
```
JWT_ACCESS_TIME=30s
JWT_ACCESS_TIME=7h
JWT_REFRESH_TIME=30d
REDIS_HOST=192.168.100.101
REDIS_PORT=6379
DB_CONN_STRING=mongodb://127.0.0.1:27017/nodejsjwtauth
MAIL_HOST=smtp.ethereal.email
MAIL_PORT=587
MAIL_USER=cecile.leffler67@ethereal.email
MAIL_PASS=7TfEXqF2GQcmDRGN82
MAIL_FROM="Cecile Leffler <cecile.leffler67@ethereal.email>"
```
- Deffi-Hellman key exchange setup

View File

@ -4,6 +4,7 @@ const {
GenerateAccessToken,
GenerateRefreshToken,
} = require('../services/auth.service')
const Mailer = require('../services/mail.service')
async function Register(req, res, next) {
// encrypt password
@ -37,6 +38,13 @@ async function Register(req, res, next) {
try {
const saved_user = await user.save()
Mailer.sendMail({
to: saved_user.email,
subject: 'Welcome to the app',
text: `Welcome to the app, ${saved_user.username}`,
})
res.json({
status: true,
message: 'Registered successfully.',

View File

@ -7,28 +7,34 @@ const cors = require('cors')
const app = express()
const connectMongo = require('./helpers/mongo_connect')
const checkENV = require('./utils/checkENV.utils')
const err_routes = require('./utils/errorHandler.utils')
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(morgan('tiny'))
app.use(cors())
// Connect to MongoDB and Config Checking
;(async () => {
try {
await connectMongo()
await checkENV()
setTimeout(async () => {
console.log('Connecting to MongoDB ...')
await connectMongo()
console.log('Checking Config ...')
await checkENV()
}, 1000)
} catch (error) {
console.log(error.message)
process.exit(1)
}
})()
const err_routes = require('./utils/errorHandler.utils')
console.log('Auto Loading routes 🎩 ...')
fs.readdirSync('./routes/').forEach(function (file) {
console.log('Loading route: /' + file.split('.')[0])
app.use(`/${file.split('.')[0]}`, require('./routes/' + file))
})
console.log('Loaded all routes 🎩 ...')
app.use('*', err_routes.notFound)
app.use(err_routes.logErrors)