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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@growishpay/nodejs-utils

v1.1.2

Published

GrowishPay NodeJS utils

Downloads

111

Readme

@growishpay/nodejs-utils

GrowishPay nodejs utils


Descrizione

@growishpay/nodejs-utils è una libreria utility per node.js Fornisce moduli per logging, gestione connessione mongoose, notifier, plugin mongoose, salesforce ed express


Requisiti

  • Node.js >= 16.0.0
  • Peer dependencies:
    • express >= 4.0.0
    • mongoose >= 7.0.0

Installazione

La libreria si può installare via npm

npm install @growishpay/nodejs-utils

Importazione e utilizzo

La libreria supporta sia ESM che CommonJS.

Import named (con destructuring)

import {
  logger,
  notifier,
  mongoose,
  express,
  gracefulShutdown,
  createAutoloader
} from '@growishpay/nodejs-utils';

logger.info('Logger attivo');

Import default (senza destructuring)

import utils from '@growishpay/nodejs-utils';

utils.logger.info('Logger attivo');
await utils.mongoose.connect(/* ... */);

CommonJS

Named import con destructuring:

const {
  logger,
  notifier,
  mongoose,
  express,
  gracefulShutdown,
  createAutoloader
} = require('@growishpay/nodejs-utils');

logger.info('Logger attivo');

Default import:

const utils = require('@growishpay/nodejs-utils');

utils.logger.info('Logger attivo');

Moduli principali

logger

Modulo di logging basato su winston, configurato per rotazione giornaliera dei file.

logger.info('Informazione di log', { tag: 'mioComponente'});
logger.error('Errore registrato', { tag: 'mioComponente', error});

express

express.apiMiddleware

Express middleware per standardizzare le risposte api

import express from 'express';
import utils from '@growishpay/nodejs-utils';

const app = express();
app.use(utils.express.apiMiddleware);

express.logger

Express utilities per logging delle richieste HTTP, basato su morgan.

import express from 'express';
import utils from '@growishpay/nodejs-utils';

const app = express();
app.use(utils.express.logger);

express.routeHandler

Express utilities per definire una nuova rotta api con metodi chainable

import express from 'express';
import utils from '@growishpay/nodejs-utils';

const app = express();

utils.express.routeHandler.routeController(tag)
    .setMethod('get')
    .setRoute('/')
    .controller(async (req, res, logger) => {
        res.send({"message": "ok"});
    });

notifier

Modulo per inviare notifiche su canale slack tramite webhook. utile per notifiche di alert o messaggi automatici.

Esempio di utilizzo

import { notifier } from '@growishpay/nodejs-utils';

const environment = 'develop';
const botOauthToken = 'bot oauth token app slack'; // token legato all'app slack recuperabile da https://api.slack.com/apps in oauth permission
const channel = '#test'; // default channel per le notifiche, se non indicato è #general



notifier.init(environment, botOauthToken, channel); // init del notifier, lanciare prima di utilizzare nel servizio
notifier.send('Questo è un messaggio di test inviato dal modulo notifier!');

mongoose

mongoose.connect

Gestisce la connessione a MongoDB con auto riconnessione e graceful shutdown

import { mongoose } from '@growishpay/nodejs-utils';

await mongoose.connect('mongodb://localhost:27017/dbname');

mongoose.salesforPlugin

Plugin Mongoose per integrazione con salesforce.

Per funzionare correttamente è necessario definire due funzioni da passer in fase di init:

  pushFn: () => {}
  deleteFn: () => {} // opzionale
import { mongoose } from '@growishpay/nodejs-utils';

mongoose.salesfocePlugin.init(true, () => {}); // init del plugin lanciare prima di utilizzare nel servizio

const modelSchema = /** Schema definito **/
modelSchema.plugin(mongoose.salesforcePlugin, {
    assetClass: "model", addSchema: true
})

gracefulShutdown

Utilities per registrare funzione per gestire lo shutdown di un servizio in caso di signal SIGINT e SIGTERM

import { gracefulShutdown } from '@growishpay/nodejs-utils';

gracefulShutdown.register(async () => {
    // logic code 
}, 'nome');

autoloader

Utilities per caricare in lazy loading dinamico i file del progetto tramite glob pattern

import { createAutoloader } from '@growishpay/nodejs-utils';

const autoloader = createAutoloader({ verbose: true });

await autoloader.load([
  'path/plugins/*.js',
  'path/controllers/**/*.js'
]);

Build

La libreria è scritta in TypeScript e compilata con tsup.

Per buildare localmente:

npm run build

Nota: Se installi da GitHub, assicurati che la cartella dist/ sia presente nel repository, oppure esegui la build manualmente dopo l'installazione.


Versionamento e release

Si utilizza standard-version per semplificare versioning e changelog.

Per effettuare una release patch

npm run release:patch

Per effettuare una release minor

npm run release:minor

Per creare una release major

npm run release:major

Se la release viene creata con successo procedere a pushare su git e pubblicare su npm con i seguenti comandi

npm run git:push
npm publish

Dipendenze

runtime

  • semver
  • axios
  • morgan
  • winston
  • winston-daily-rotate-file
  • fast-glob

dev

  • express
  • mongoose
  • standard-version
  • typescript
  • tsup (per build)

Autore

Lorenzo Colombini
[email protected]


Licenza

ISC


Keywords

nodejs, utils, growishpay