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

awesome-express-api

v0.1.10

Published

## Overview ### Features - -

Downloads

6

Readme

Awesome-Express-Api

Overview

Features

-
-

Table of contents

Requests

Resources

Serializer

Models

Errors

Installation

npm i awesome-express-api

Initialize

import Express from 'express';
import AwesomeExpressApi from 'TODO'

const app = Express();
const pocInstance = new AwesomeExpressApi(app, DatabaseLayer, options);

// Register resources
pocInstance.addResource('customer')

// Start server
pocInstance.startServer();

Options

interface OptionsInterface {
    resetDatabase?: boolean,
    listRoutes?: boolean,
    port?: number,
    filterQueryFormat?: string,
    filterKey?: string,
    searchKey?: string,
    searchQueryFormat?: string,
    sortKey?: string,
    pageSizeKey?: string,
    pageNumberKey?: string,
    pageStartNumber?: number,
    sort?: { [keyName: string]: string },
    populateAfterPatchPost?: boolean,
    responseBuilder?: ResponseBuilderInterface
}

Custom response format at get route

The standard response format for a get route is a array with result objects. If you want additional fields in the response, you can specify a response builder and customize the response.

For usage pass a function with the following format to the responseBuilder-option:

function responseBuilder(req, databaseResult, filter, search)

Example

async function responseBuilder(req, result, filter, search) {
    const totalCount = await req.currentModel.model.countDocuments({...filter, ...search})
    const notFilteredTotalCount = await req.currentModel.model.countDocuments({})
    return {
        items: result,
        totalCount,
        notFilteredTotalCount
    }
}

const pocInstance = new AwesomeExpressApi(app, DatabaseLayer, {
    responseBuilder: responseBuilder
});

Validators

The following validators are available at the moment:

  • isString
  • minLength:NUMBER
  • maxLength:NUMBER
  • notEmpty
  • isBoolean

Access in requests

DatabaseLayer

Docker

Login to github docker to build and push new images

docker login docker.pkg.github.com -u USERNAME -p PRIVATETOKEN

Build new Image

- docker build -t docker.pkg.github.com/bobo-le/awesome-express-api/aea:TAG .
- docker push docker.pkg.github.com/bobo-le/awesome-express-api/aea:TAG

Kubernetes

Create a deployment with pods and service inside

kubectl create -f deployment.yaml

Update running pods with new image

kubectl set image deployment/DEPLOYMENTNAME LABELNAME=docker.pkg.github.com/bobo-le/awesome-express-api/aea:TAG --record

Scale Pods

- kubectl scale --replicas=COUNT -f deployment.yaml
- COUNT=0 menas stopping all

Apply new config

kubectl apply -f deployment.yaml

Create secret to pull image from private registry

- kubectl create secret docker-registry regcred --docker-server=docker.pkg.github.com --docker-username=USERNAME --docker-password=PRIVATETOKEN --docker-email=EMAIL
- "regcred" is the name of your secret. Used in deployment.yaml

Get URL for running service

- minikube service SERVICENAME --url
- the api is under this url reachable

Helm

When using helm, kubecl -f FILES doesnt work anymore out of the box. Instead use the following

Optionally using kubectl -f FILES

- helm template REPONAME -x .\templates\deployment.yaml
- this renders the template file with the correct values
- result can be piped to -f with the following line
- helm template REPONAME -x .\templates\deployment.yaml | kubectl -f -

Installing environment with helm

- helm install --name REPONAME HELMDIRECTORY
- the repo is available under the REPONAME property

Upgrading with helm

- helm upgrade REPONAME HELMDIRECTORY
- it uses rolling update