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

napim-next

v4.0.2

Published

Node Api Maker build with polka

Downloads

1

Readme

NAPIM

NPM Version NPM Downloads

Node API Maker built with polka and nodejs

Overview

The idea is to make API development quick and easy. Every single end point is handled by one file that called service. One service include:

  • Input validation
  • DB transaction (optional)
  • Input mapping
  • Error handling

Installation

  1. Install Napim CLI globally (optional)

    npm install -g napim-cli

    you can check by running napim --version

  2. Generate Napim template (optional)

    napim init project-name

    change project name with your actual project name

    for typescript support, ad -ts in the end eg:napim init project-name -ts

  3. Install dependency

    cd project-name && npm install

  4. Update Napim to current version npm install napim

File and Folder Structure

This is default folder structur for typescript mode:

.
|-- dist //compiled script will be here
|-- log //all error log will be here
|-- src
    |-- middleware
    |-- model
    |-- service
|-- stub //napim template generator, edit the template to match your needs
    |-- middleware.napim
    |-- model.napim
    |-- service.napim
    index.ts //your main js file
|-- .env
|-- .gitignore
|-- knexfile.js // by defaut napim use knex for Database Query Builder, delete it if you use nosql like mongo
|-- package.json
|-- router.json //this file will map your API endpoint to execute service file
|-- tsconfig.json

Generate NAPIM File

  • Generate Service

    napim make:service service-name

    by default service have method GET, you can change by append the method argument in the end, eg:

    napim make:service login --post

    this command will create file login_post.ts in service folder and append route data to router.json with tag: "default" inside post array, just check it :)

    By default, prefix for default tag is api, so you can execute the service by access endpoint POST:[host]/api/login

    If you want to add some tag, for example secure (You can add middleware like Auth later), add tag argument

    napim make:service users --tag=secure

    You can also make dynamic endpoint, for example find user by some id

    napim make:service users/:id

  1. Generate Model

    If you use Model like Objection.js to you can generate Objection model by

    napim make:model ModelName

    if you prefer to use raw query, just import {db} from "napim" and use it like db.query(trx)... see knex documentation for detail

    If you want to use db transaction, just change transaction to true in your service file, ez

    You like NoSQL like mongo, just edit your .env add DB_DRIVER=mongo and create your own Model or Schema and import to your service like usually

    TODO: implement db transaction for mongo

  2. Generate Middleware

    Want to make Auth, JWT, or handle uploaded file (eg: using multer) you can create it in middleware

    napim make:middleware JWT

    then use it in router, append it in middleware array for example:

    //router.json
    [
        {
            "tag": "default",
            "prefix": "/api",
            "middleware": [],
            "get": [],
            "post": [
                {
                    "path": "/login",
                    "service": "/login_post"
                }
            ]
        },
        {
            "tag": "secure",
            "prefix": "/api/secure",
            "middleware": [
                "JWT"
            ],
            "get": [
                {
                    "path": "/products/:id",
                    "service": "/products/_id_get"
                }
            ]
        },
        {
            "tag": "admin",
            "prefix": "/api/admin",
            "middleware": [
                "JWT",
                "Admin"
            ],
            "get": [
                {
                    "path": "/products",
                    "service": "/products_get"
                }
            ],
            "post": [
                {
                    "path": "/products",
                    "service": "/products_post"
                }
            ],
            "delete": [
                {
                    "path": "/products/:id",
                    "service": "/producst/_id_delete"
                }
            ],
            "patch": [
                {
                    "path": "/products/:id",
                    "service": "/producst/_id_patch"
                }
            ]
        }
    ]

    Polka App Instance

    If you want to access polka instance, just import {app} from "napim"