Beatific
A single npm package which satisfies the need for the following packages:
- mongoose => For establishing connection to your MongoDB and producing mongoose models.
- bcryptjs => For hashing and verifying hashes.
- helmet => For securing Express apps by setting various http headers.
- compression => For the compression of route propagation.
- jsonwebtoken => For generating and verifying JWTs.
- morgan => For logging every request made to your backend.
It also generates the dockerfile for your project :)
## Usage:
Installation:
npm install --save beatific
API:
var beatific = ;
MongoDB/Mongoose Functionality:
- Connect to a MongoDB
Parameters: MongoDB URI
beatific ;
- Create a mongo schema and automatically generate a mongoose.model for it
Parameters: Schema name, schema object, db collection name (optional)
let userSchema = name: type: String required: true email: type: String required: true unique: true ; beatific ;
What this does behind the scenes
const mongoose = ; let userSchema = name: type: String required: true email: type: String required: true unique: true ; let schema = userSchema; return mongoose;
JWT functionality:
- Signing/Generating the token:
Parameters: data, secret, expiresIn (optional)
beatific ;
- Verifying/Decoding the token:
Parameters: token, secret
beatific ;
Bcrypt Functionality:
- Hashing some data:
Parameters: data, salt rounds (default=10)
beatific ;
- Verifying/Comparing some data and corresponding hash:
Parameters: hashed data, inputData
beatific ;
Use logger
Parameters: loggerType (default = "dev")
//In your main .js file var app = ;loggerType = "short"; // For example app;
Use helmet:
// In your main .js filevar app = ; app;
Use compression:
// In your main .js filevar app = ; app;
Generate Dockerfile for the project
Parameters: dockerfile_name (default="dockerfile"), portNumber, startCommand (default="npm start")
Just run this once in your main .js file:
beatific;