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

@snipkode/stack

v5.1.4

Published

Node JS Stack Fast Configuration

Downloads

65

Readme

ENVIRONMENT REQUIREMENT

| NODE VERSION | NPM VERSION | |--------------|-------------| | 14.19.3 | 6.x.x |

PROJECT STRUCTURE APPLICATION

    / stackproject
    └── public
        └── assets
        └── certs
    └── repository
        └── admin
            └── ejs-app-1
            └── ejs-app-2
        └── clients
            └── react-app-1
            └── react-app-2
    └── servers
        └── controller
            └── middleware
            └── ModuleControl.js
        └── model
            └── connection
            └── ModuleModel.js
        └── routes
            └── ApiRoutes.js
            └── WebRoutes.js

COPY THE CODE BELOW TO GET TESTING INTO NPM RUN KIT (node 14.x.x) OR VISIT THIS LINK https://admhabits.github.io/snipkode-stack/

    
require("@google-cloud/firestore");
const Stack = require("@snipkode/stack");
const Routes = Stack.router();
const Jwt = Stack.jwt;

Routes.get('/', (req, res) => {
    console.log(Jwt.sign('a', 'b')); // return eyJhbGciOiJIUzI1NiJ9.YQ.PrSVmEzsOLiTgzWfslar1L11W5nJXm8Vj0OFoGYUIjs
    const token = "eyJhbGciOiJIUzI1NiJ9.YQ.PrSVmEzsOLiTgzWfslar1L11W5nJXm8Vj0OFoGYUIjs";
    Jwt.verify(token, 'b', function(err, decoded) {
        console.log(decoded) // return a
    });
   return res.status(Stack.status.OK).send({
        message: 'hello world!'
    });
});

const stackType = 'default';
const stackData =  [
    {
        AppType: 'apis',
        AppPort: 8234,
        AppRoutes: Routes,
        AppPath: false,
 
    },
]
 
Stack.initializeApp({
    type: stackType, secure: false,
    servers: stackData
});
   

ALL STACK METHOD UTILITIES

| METHOD | RETURN TYPES | ARGUMENT | |------------------|--------------|-------------------------------------------------------------| | initializeApp | void | Object config | | createConnection | void | Object connection | | router | void | String route, callback(req, res) | | removeFile | void | String filePath, String fileName | | renameFile | void | String oldPath, String newPath, String fileName | | upload | void | Object { dest: './storages/' } | | arrayToObject | object | Arrays | | isEmpty | boolean | Object request body | | getDirectory | String | String path |

SETUP INITIALIZE APPLICATION


import Stack from '@snipkode/stack';

import ApiRoutes from 'path/to/routes/ApiRoutes';
import WebRoutes from 'path/to/routes/WebRoutes';

const stackType = process.env.NODE_ENV == 'production' ? 'extends' : 'default';
const stackData =  [
    {
        AppType: 'apis',
        AppPort: 8234,
        AppRoutes: ApiRoutes,
        AppPath: false,

    },
    {
        AppType: 'admin',
        AppPort: 9443,
        AppRoutes: WebRoutes,
        AppPath: '/admin',
    },
    {
        AppType: 'client',
        AppPort: 8000,
        AppRoutes: false,
        AppPath: '/clients',
    }
]

Stack.initializeApp({
    type: stackType, secure: true,
    servers: stackData
});

CREATE CONNECTION MODULE


import Stack from "@snipkode/stack";

const dataConnection = {
    admin: {
        name: 'stackadmin',
        user: 'root',
        pass: '',
        options: {
            host: 'localhost',
            dialect: 'mysql',
            timezone: '+07:00'
        }
    },
    client: {
        name: 'stackclient',
        user: 'root',
        pass: '',
        options: {
            host: 'localhost',
            dialect: 'mysql',
            timezone: '+07:00'
        }
    }
}
const connect = Stack.createConnection(dataConnection);

export default connect;

CREATE MODEL PATTERN MODULE


import connect from 'path/to/connection';
import Stack from "@snipkode/stack";

export const Users = connect.admin.define('users', {
    email: {
        type: Stack.schema.STRING()
    },
    password: {
        type: Stack.schema.CHAR(12)
    }
})

CREATE CONTROLLER CLASS MODULE


import { Users } from "path/to/UserModel";

export default class UsersController {
    static getUsers = async (req, res) => {
        try {
            const getUsers = await Users.findAll();
            if(!getUsers){
                res.status(404).send({
                    message: 'Tidak ditemukan data!'
                })
            }
            res.status(200).send({
                message: 'Data ditemukan!',
                data: getUsers
            })
        } catch (error) {
            res.status(500).send({
                message: error.message
            })
        }
    }
}

CREATE ROUTING STACK MODULE


import Stack from '@snipkode/stack'; 

import UsersController from 'path/to/controller/UsersController';

const ApiRouter = Stack.AppRouter();

ApiRouter.get('/', UsersController.getUsers);
ApiRouter.get('/users/:id', UsersController.updateUsers);

export default ApiRouter;

import { router } from '@snipkode/stack'; 

import UsersController from 'path/to/controller/UsersController';

const ApiRouter = router();

ApiRouter.get('/', UsersController.getUsers);
ApiRouter.get('/users/:id', UsersController.updateUsers);

export default ApiRouter;

FILE SYSTEM METHOD

    const ApiRouter = router();
    ApiRouter.get('/', upload({ dest: './storages/books/'}).single('thumb'), (req, res) => {
        console.log(req.file);
        const new_path_file = `${req.file.destination}/${req.file.filename}.${req.file.mimetype.split('/')[1]}`;
        const path_file_removed = `${req.file.destination}/a36094022797a4a1512133fcc1d57173.jpeg`;
        renameFile(req.file.path, new_file_path);
        removeFile(path_file_removed);
        res.send({
            message: 'hi'
        })
    });

HANDLE STATUS CODE RESPONSE


    import Stack, { status } from '@snipkode/stack';

    Stack.AppRouter.get('/', (req, res) => {
       return res.status(status.OK).send({
            message: 'hi'
        });
    });

STATUS CODE REFERENCE

    CONTINUE: "100",
    SWITCHING_PROTOCOLS: "101",
    PROCESSING: "102",
    OK: "200",
    CREATED: "201",
    ACCEPTED: "202",
    NON_AUTHORITATIVE_INFORMATION: "203",
    NO_CONTENT: "204",
    RESET_CONTENT: "205",
    PARTIAL_CONTENT: "206",
    MULTI_STATUS: "207",
    MULTIPLE_CHOICES: "300",
    MOVED_PERMANENTLY: "301",
    MOVED_TEMPORARILY: "302",
    SEE_OTHER: "303",
    NOT_MODIFIED: "304",
    USE_PROXY: "305",
    TEMPORARY_REDIRECT: "307",
    BAD_REQUEST: "400",
    UNAUTHORIZED: "401",
    PAYMENT_REQUIRED: "402",
    FORBIDDEN: "403",
    NOT_FOUND: "404",
    METHOD_NOT_ALLOWED: "405",
    NOT_ACCEPTABLE: "406",
    PROXY_AUTHENTICATION_REQUIRED: "407",
    REQUEST_TIME_OUT: "408",
    CONFLICT: "409",
    GONE: "410",
    LENGTH_REQUIRED: "411",
    PRECONDITION_FAILED: "412",
    REQUEST_ENTITY_TOO_LARGE: "413",
    REQUEST_URI_TOO_LARGE: "414",
    UNSUPPORTED_MEDIA_TYPE: "415",
    REQUESTED_RANGE_NOT_SATISFIABLE: "416",
    EXPECTATION_FAILED: "417",
    UNPROCESSABLE_ENTITY: "422",
    LOCKED: "423",
    FAILED_DEPENDENCY: "424",
    UNORDERED_COLLECTION: "425",
    UPGRADE_REQUIRED: "426",
    PRECONDITION_REQUIRED: "428",
    TOO_MANY_REQUESTS: "429",
    REQUEST_HEADER_FIELDS_TOO_LARGE: "431",
    INTERNAL_SERVER_ERROR: "500",
    NOT_IMPLEMENTED: "501",
    BAD_GATEWAY: "502",
    SERVICE_UNAVAILABLE: "503",
    GATEWAY_TIME_OUT: "504",
    STATUS_VERSION_NOT_SUPPORTED: "505",
    VARIANT_ALSO_NEGOTIATES: "506",
    INSUFFICIENT_STORAGE: "507",
    BANDWIDTH_LIMIT_EXCEEDED: "509",
    NOT_EXTENDED: "510",
    NETWORK_AUTHENTICATION_REQUIRED: "511"