npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

core-sys-utils

v0.2.7

Published

Common Functions for Node JS applications

Downloads

18

Readme

Node.js Core Utilities

npm Build Status codecov Known Vulnerabilities

The core-sys-utils library exported as Node.js Modules.

Installation

Using npm

npm install core-sys-utils

Setting up .env

Most of the tools need your credentials to work. You can either

JWT_SECRET = "SecretKey0123456789XYZ"
AUTH_TOKEN_VALIDITY = "1" // Days

# ================ GOOGLE CLOUD ================== #
GOOGLE_SERVICE_ACCOUNT_EMAIL = "[email protected]"
GOOGLE_PRIVATE_KEY = "-----BEGIN PRIVATE KEY-----\n********\n-----END PRIVATE KEY-----\n"

# ================ KONG ADMIN ==================== #
KONG_URL = "http://localhost:8001"

#================ EMAIL CREDENTIALS ============== #
ELASTICEMAIL_USERNAME = "[email protected]"
ELASTICEMAIL_API_KEY = ""
ELASTICEMAIL_FROM_NAME = "CORE"

# ================= S3 BUCKET =================== #
S3_SECRET_ACCESS_KEY = "3wecX/pC69EKR"
S3_ACCESS_KEY_ID = "AKIA35WALCHNP5J"
S3_REGION = "ap-south-1"
S3_BUCKET = "core"
S3_VERSION = "v4"
S3_ACL = "public-read"

Note: you could use .env file to configure these variables.

In Node.js

Import the package functions and it's usages

Logger

// Import logger from package
const { logger } = require("core-sys-utils");

// Call this function for information messages
logger.info(`Your Message`);

// Call this function for exceptions
logger.error(new Error(`Exception`))

/**
 * Capture all api requests and responses
 * from middleware
 */
const app = express();
app.use(logger.captureRequests)

Email Service

// Import emailService from package
const { emailService } = require("core-sys-utils");

/**
 * Send email
 * @param {*} html // HTML content
 * @param {*} data // HTML template data object
 * @param {*} subject // Email Subject message
 * @param {*} msgTo // Receiver email address
 * @param {*} cc // array of email address to add cc list
 * @param {*} attachment array of files to be attached
 * @returns
 */
emailService.sendEmail(html, data, subject, msgTo, cc, attachment);

KONG Service

// Import kongService from package
const { kongService } = require("core-sys-utils");

JWT Service

// Import jwtService from package
const { jwtService } = require("core-sys-utils");

/**
 * Generate JWT Token with expiry
 * @param {*} data
 * @param {*} exp
 * @returns
 */
jwtService.generateToken({sample: "test"}, expTimeStamp)

/**
 * Verify JWT Token
 * @param {*} token
 * @returns
 */
jwtService.verifyToken(token);

S3 Service

// Import s3Service from package
const { s3Service } = require("core-sys-utils");

API Response

const { response } = require("core-sys-utils");

/**
 * Success response
 * @param {*} res route response param
 * @param {*} message // string
 * @param {*} data // data object
 * @param {*} code // status code
 */
response.success(res, message, data, code);

/**
 * Failure response
 * @param {*} res route response param
 * @param {*} message // string
 * @param {*} code // status code
 * @param {*} error // error object 
 */
response.failure(res, message, code, error);

/**
 * Crash response
 * @param {*} res route response param
 * @param {*} error // Exception error
 */
response.crash(res, error);

Helpers

const { helpers } = require("core-sys-utils");

Troubleshooting

If you encounter an error that you cannot fix by yourself, please

  1. Make sure you update package to the latest version
  2. Try again with the environment variable set and open an issue at https://github.com/nodejs/core-sys-utils/issues with detailed logs.

Support

Tested in Chrome 74-75, Firefox 66-67, IE 11, Edge 18, Safari 11-12, & Node.js 8-12. Automated browser & CI test runs are available.

License

MIT. See LICENSE.