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

erstwhile-backend

v0.1.10

Published

This is the backend portion for the Erstwhile Framework. Currently focused on the API description.

Downloads

16

Readme

erstwhile-backend

erstwhile-backend is a Node module meant to help build ExpressJS backends that are compatible with the Erstwhile Javascript framework.

When Erstwhile uses an API, it looks for a JSON file that describes the endpoints available, data strucures used by the endpoints, authentication information, and other details. This package helps backend applications publish that file, and also provides for an HTML display of that file that can serve as built-in developer documentation when looking at a development server.

It also provides some convenient helper functions for validating data based on that API description.

Installation

npm install --save erstwhile-backend

Usage

Required Environment Variables

ERSTWHILE_DESCRIPTION_PATH=./config/description.json
ERSTWHILE_SESSION_KEY=session

ERSTWHILE_DESCRIPTION_PATH should point to your description.jsonfile. ERSTWHILE_SESSION_KEY should be the key on the request object where you store the logged in user's user_id. This presence of (by default) req['session'].user_id is used to determine if the user is authenticated.

Publishing description.json

Within your application's app.js:

const {handleDescribe} =  require("erstwhile-backend");

if(process.env.ENVIRONMENT != 'production') {
  app.get('/describe', handleDescribe)
}

The path /describe is the normal place to put this file, but you can also use something else if that doesnt' work in your environment. To see the HTML version of the description try /describe?format=html in the brower.

Validating Requests

const { validateRequest } =  require("erstwhile-backend");

/*
 * If the request itself contains everything you need to properly 
 * validate, you can use the short form of the method.
let  validRequest1  =  validateRequest(req);
/*
 * For updates, you may want to include the existing object as well
 * as the request, as requests might not contain all of the keys needed
 * to properly validate.
 */ 
let  validRequest2  =  validateRequest(req, existingObject);

/* 
 * If the request is invalid, validRequest conains a properly formatted
 * Erstwhile standard response you can pass back to the user.
 */
if(validRequest.success) {
 // continue
else {
  res.send(validRequest)
}

Please note that if req[process.env.ERSTWHILE_SESSION_KEY || 'session']?.user_id is falsy, the authenticated key in the standard response will be false.