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

@ducbaovn/nodejs-common

v1.0.3

Published

Name: @ducbaovn/nodejs-common Current Version: 1.0.1 ## Connections 1. AMQP Connection: - This class is for establish connection to AMQP server. - Implementing publish-subscribe pattern for asynchronous inter-service communication among services ``` expor

Downloads

5

Readme

NodeJS Common Library

Name: @ducbaovn/nodejs-common Current Version: 1.0.1

Connections

  1. AMQP Connection:
  • This class is for establish connection to AMQP server.
  • Implementing publish-subscribe pattern for asynchronous inter-service communication among services
export declare class AmqpConnection {
    protected channel: Channel;
    protected config: AmqpConfig;
    protected constructor(config?: AmqpConfig);
    get connectionString(): string;
    static connect(config?: AmqpConfig): Promise<AmqpConnection>;
    publishTopic(exchange: string, key: string, msg: string): Promise<void>;
    consumeTopic(exchange: string, keys: string[], cb: (msg: ConsumeMessage | null) => void): Promise<void>;
}
  1. MongoDB Connection:
  • This class is for establish connection to MongoDB server.
  • Using in service which do not need fixed schema and do not need strong consistency such as our activity-service
export declare class MongoDbConnection {
    protected mongoClient: Db;
    protected config: MongoDbConfig;
    constructor(config?: MongoDbConfig);
    getClient(): Db;
    get connectionString(): string;
    connect(): Promise<void>;
}
  1. MySQL Connection:
  • This class is for establish connection to MySQL server.
  • Using in service which need fixed-relational schema, strong consistency, such as our product-service
export declare class SqlConnection {
    protected instance: Knex;
    protected config: SqlConfig;
    constructor(config?: SqlConfig);
    migration(): Promise<void>;
}

Enums

Sharing constants for all services

Errors

Custom Exception Class for consistent error http response

export declare class ApiError implements Error {
    name: string;
    stack: any;
    message: string;
    code: string;
    httpStatus: number;
    rawError: Error;
    static fromError(error: Error, errorCode?: ErrorCode, httpStatus?: number, stack?: boolean): ApiError;
    constructor(errorCode?: ErrorCode, httpStatus?: number, stack?: boolean);
    toString(): string;
    toErrorCode(): ErrorCode;
}

Middlewares

  1. CORS: Set response headers to support CORS
  2. Http Log: Logging Http Request Information: method, url, duration, http status, correlationId. We should use this middleware after Log Middleware
  3. Log Middleware: init our custom Logger Service
  4. Not Found Middleware: fallback to this middleware if route is not define in routers
  5. Recover: fallback unhandled exception to our custom exception

Services

  1. Logger Service: custom logger support correlationId
export declare class LoggerService {
    private _level;
    private _correlationId;
    logger: winston.Logger;
    constructor(options?: {
        level: string;
        correlationId?: string;
    });
    get correlationId(): string;
    error(message: any, context?: any): void;
    warn(message: any, context?: any): void;
    log(message: any, context?: any): void;
    verbose(message: any, context?: any): void;
    debug(message: any, context?: any): void;
    write(level: string, message: any, context?: any): void;
    private format;
}

Utils

  1. Request Helper:
  • Wrapper of got library. It introduces simplier interface than got
  • Use for synchronous inter-service communication between services
export interface ReqOptions {
    body?: any;
    headers?: any;
    searchParams?: any;
    basicAuth?: {
        username: string;
        password: string;
    };
    p12Auth?: {
        pfx: Buffer;
        passphrase: string;
    };
    timeout?: number;
    retry?: number;
}
export declare class ResponseDto {
    statusCode: number;
    body: any;
    headers: any;
    constructor(statusCode: number, body: any, headers: any);
}
export declare class RequestHelper {
    static get(url: string, options?: ReqOptions): Promise<ResponseDto>;
    static post(url: string, body: any, options?: ReqOptions): Promise<ResponseDto>;
    static put(url: string, body: any, options?: ReqOptions): Promise<ResponseDto>;
    static delete(url: string, options?: ReqOptions): Promise<ResponseDto>;
    static patch(url: string, body: any, options?: ReqOptions): Promise<ResponseDto>;
    static stream(method: Method, url: string, options?: ReqOptions): Duplex;
    static send(method: Method, url: string, options?: ReqOptions): Promise<ResponseDto>;
    private static buildRequestParams;
    private static transform;
}

Express Application

Wrapper Express Http Server. It has already installed some middlewares that I think they are will be used across services