Skip to content
An npm package which makes sure that you won't need to install mongoose, bcryptjs, jsonwebtoken and many more packages, ever again !! PS: it even generates a dockerfile for you :)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sub_libs Fixed the function params May 14, 2019
tests Done with all the tests May 14, 2019
.dockerignore First and probably the last major commit for the first version :P May 13, 2019
.gitignore First and probably the last major commit for the first version :P May 13, 2019
.travis.yml back to dockerfile based ci May 14, 2019
CODE_OF_CONDUCT.md Added necessary markdown files May 16, 2019
CONTRIBUTING.md Added necessary markdown files May 16, 2019
LICENSE First and probably the last major commit for the first version :P May 13, 2019
README.md Merge pull request #2 from mayankshah1607/master May 16, 2019
app.js Added Mongoose schema generator May 14, 2019
dockerfile
package-lock.json First and probably the last major commit for the first version :P May 13, 2019
package.json changed version May 16, 2019

README.md

Beatific

npm version Build Status MIT License PRs Welcome npm

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 :)


Installation

npm install --save beatific

Usage

API

var beatific = require("beatific");

MongoDB/Mongoose Functionality:

  • Connect to a MongoDB

Parameters: MongoDB URI

beatific.mongoConnect(dbURI)
.then(db => console.log("Connected to the DB..."))
    .catch(err => console.error("Error connecting to the DB!"));
  • 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.mongoModelGen('User', userSchema, "users")
.then(model => console.log("mongoose.model generated for user schema"))
     .catch(err => console.error("Some problem occurred"));

What this does behind the scenes

const mongoose = require("mongoose");

let userSchema = {
   name: {
      type: String,
      required: true
   },
   email: {
      type: String,
      required: true,
      unique: true
   }
};

let schema = new mongoose.schema(userSchema);

return mongoose.model('User', schema, "users");

JWT functionality

  • Signing/Generating the token:

Parameters: data, secret, expiresIn (optional)

beatific.generateJWT({message: "Hey there"}, 'something_secret', '4d')
.then(token => console.log("Here's the token " + token))
   .catch(err => console.error("Some problem occurred"));

  • Verifying/Decoding the token:

Parameters: token, secret

 beatific.decodeJWT('my_token_1234321', 'something_secret')
.then(decoded => console.log("Here's the decoded token " + decoded))
   .catch(err => console.error("Some problem occurred"));

Bcrypt Functionality

  • Hashing some data:

Parameters: data, salt rounds (default=10)

beatific.hashGen("hey there", 8)
.then(hash => console.log("Here's the hash " + hash))
    .catch(err => console.error("Some problem occurred"));

  • Verifying/Comparing some data and corresponding hash:

Parameters: hashed data, inputData

beatific.hashCheck("$adfdsf23243546524", "my password may be")
.then(valid => console.log("Status of check: " + valid))
   .catch(err => console.error("Some problem occurred"));

Use logger

Parameters: loggerType (default = "dev")

//In your main .js file

var app = express();
loggerType = "short"; // For example

app.use(beatific.logger(loggerType));

Use helmet

// In your main .js file
var app = express();

app.use(beatific.helmet());

Use compression

// In your main .js file
var app = express();

app.use(beatific.compression());


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.dockerGen("dockerfile.dev", 8000, "npm test");

License

MIT

You can’t perform that action at this time.