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

module-connector

v1.0.9

Published

object used to connect different backend and frontend components. in order to better control the different scenarios that could occur with the communication of these

Downloads

15

Readme

module-connector

object used to connect different backend and frontend components. in order to better control the different scenarios that could occur with the communication of these

structure

| Attribute | Type | Default | Description | | ------------- | :-------------: | :-------------: | ------------- | | success | boolean | false | tells us if the process that the component is in charge of is completed successfully or not | | message | string | module_connector | a message is left here depending on the conclusion of the component. for example: created_user, existing_name, id_no_found | | response | array / object | [] | All the content that should come from the component is sent here, it can be a list, an element as such, but never a string, boolean or integer value, for reasons of scalability | | code | integer | 500 | HTTP code |

Simple example

although the component is called a module connector. The most recommended is to define a variable with the name of output when creating a new connector, since it is more readable. it is also recommended to define it as let so that it never deceives us with other classes, functions or services


//include library
let moduleConnector = require("module-connector");

//create default output from module connector
let output = new moduleConnector();

//you code
let arrayClientList = [
    { id:1, name: "diana" },
    { id:2, name: "jorge" }
];

//modify output
output.success = true;
output.message = "array_clients_list";
output.code = 200;
output.response = arrayClientList;

//return output
return output;

Example with http-based methods

using http-based methods it is possible to shorten the previous sentence making it smaller and more readable

Success methods

in this case using the ok() for send a success true response with code 200. same as the previous example


//include library
let moduleConnector = require("module-connector");

//create default output from module connector
let output = new moduleConnector();

//you code
let arrayClientList = [
    { id:1, name: "diana" },
    { id:2, name: "jorge" }
];

//modify output
output.ok( arrayClientList, "array_clients_list" );

//return output
return output;

also can define another message when new instance is create:



//create default output from module connector
let output = new moduleConnector( "another_default_message" );

Faileds methods

in this case using the badRequest() for send a success false response with code 400.


// for output with response and message
output.badRequest( arrayClientList, "array_clients_list" );

// this return
{
    success : false,
    message : "array_clients_list",
    code : 400,
    response : [
        { id:1, name: "diana" },
        { id:2, name: "jorge" }
    ]
}

also if you don't have an object to add to your output you can just write the message (this also applies to successful responses)

// for output with message only
output.badRequest( "array_clients_list" );

// this return
{
    success : false,
    message : "array_clients_list",
    code : 400,
    response : []
}

Methods

it is recommended that all requests with code 2XX are always true and that 3XX, 4XX and 5XX are always false | Method Name | Success | Code | | :------------- | :-------------: | :-------------: | | .ok() | true | 200 | | .created() | true | 201 | | .accepted() | true | 202 | | .nonAuthoritative() | true | 203 | | .noContent() | true | 204 | | .badRequest() | false | 400 | | .unauthorized() | false | 401 | | .forbidden() | false | 403 | | .notFound() | false | 404 | | .conflict() | false | 409 |