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

@pauliclark/eez

v1.0.2

Published

Base server

Downloads

3

Readme

eez

eez is a wrapper for express, to handle errors and provide container access

Starting the instance of the server

import eez from 'eez'

eez({})

This will start a server, but will select an available port and will not have any defined routes or controllers.

Parameters

env

The 'env' parameter sent to EEZ will be validated against the constants file for environments./constants/environments).

The Environment is stored in a container, that exposes two methods 'getEnv', and 'createEnvironment'.

import {getEnv} from 'eez'
console.log( getEnv() )
import {eez, environments, getEnv, createEnvironment} from 'eez'
const newEnvironment = 'myNewEnv'
// create a custom environment
createEnvironment( newEnvironment )
console.log(environments.MYNEWENV) // outputs 'mynewenv'

// create an eez instance with the environment
eez({
  env: newEnvironment,
  afterListen: () => {
    console.log( getEnv() ) // outputs 'mynewenv'
  }
})

port

This is the port the http server is to listen on.

There are two identifiers that can be be applied instead.

  • autoPort Tells the server to find an available port to use
  • noPort Tells the server not to listen at all

To find an available port

import { eez, identifiers, environments } from 'eez'

eez({
  env: environments.DEV,
  port: identifiers.autoPort
})

To listen to a specific port

import { eez, identifiers, environments } from 'eez'
const port = 8080
eez({
  env: environments.DEV,
  port
})

To prevent listening

import { eez, identifiers, environments } from 'eez'
eez({
  env: environments.DEV,
  port: identifiers.noPort
})

logger

If using a custom logger e.g. log-context, then it can be applied here.

import { eez, environments } from 'eez'
import { contextLog } from '@pauliclark/log-context'
const eezLog = contextLog('eez')
const port = 8080
eez({
  env: environments.DEV,
  port,
  logger: eezLog
})

Defaults to a context log as defined in the example above.

beforeApp

'beforeApp' is a triggered callback, fired before the express App is created

import { eez, environments } from 'eez'
const port = 8080
eez({
  env: environments.DEV,
  port,
  beforeApp: () => {
    console.log( 'App about to be created' )
  }
})

afterApp

'afterApp' is a triggered callback, fired just after the express App is created

import { eez, environments, getApp } from 'eez'
const port = 8080
eez({
  env: environments.DEV,
  port,
  afterApp: () => {
    console.log( 'App has just been created created' )
  }
})

afterListen

'afterListen' is a triggered callback, fired once the express App has begun listening to the port

import { eez, environments, getApp } from 'eez'
const port = 8080
eez({
  env: environments.DEV,
  port,
  afterListen: () => {
    console.log( 'App has started listening' )
    // Start defining the controllers
  }
})

Importable

getApp

'getApp' returns the express App that EEZ created

import { eez, environments, getApp } from 'eez'
const port = 8080
eez({
  env: environments.DEV,
  port,
  afterApp: () => {
    console.log( getApp() ) // outputs the instance of the Express App
  }
})

getServer

'getServer' returns the http server that EEZ created

import { eez, environments, getServer } from 'eez'
const port = 8080
eez({
  env: environments.DEV,
  port,
  afterApp: () => {
    console.log( getServer() ) // outputs the instance of the http server
  }
})

environments

'environments' is the container for the pre-defined enviroments and any custom enviroments added.

The pre-defined values are:

{
  DEVELOPMENT: 'development',
  DEV: 'development',
  TEST: 'test',
  STAGING: 'staging',
  PRODUCTION: 'production',
  PROD: 'production'
}

You can see that DEV and PROD are aliases.

getEnv

'getEnv' returns the environment that was detected

import { eez, environments, getEnv } from 'eez'
const port = 8080
eez({
  env: environments.DEV,
  port,
  afterApp: () => {
    console.log( getEnv() ) // outputs 'development'
  }
})

This is particularly useful for building config schemas.

createEnvironment

'createEnvironment' provides a method to create a custom environment

import { eez, environments, getEnv, createEnvironment } from 'eez'
const port = 8080

createEnvironment('MyCustomEnv')
console.log(environments.MYCUSTOMENV)  // outputs 'mycustomenv'

eez({
  env: 'MyCustomEnv', // will get cased to match the environments convention
  port,
  afterApp: () => {
    console.log( getEnv() ) // outputs 'mycustomenv'
  }
})

Once the custom environment is defined, it is accessible using the 'environments' container, but UPPERCASE.

The value of the enviromnet is lowercase.

The contents of the environments container will then look like this:

{
  DEVELOPMENT: 'development',
  DEV: 'development',
  TEST: 'test',
  STAGING: 'staging',
  PRODUCTION: 'production',
  PROD: 'production',
  MYCUSTOMENV: 'mycustomenv'
}

getInfo

'getInfo' is a fetch method on the info container, which only used to record the port at the moment. If you are using 'autoPort', then you may wish to know which port is being used.

import { eez, environments, identifiers, getInfo } from 'eez'

eez({
  env: environments.DEV,
  port: identifiers.autoPort,
  afterListen: () => {
    console.log( getInfo('port') ) // outputs the port found to be available and therefore used
  }
})

routing

The 'routing' object allows for methods to be applied to a particlar path, used by your controllers.

The exposed methods are:

  • get

  • put

  • patch

  • fetch

  • post

import { eez, environments, routing, response } from 'eez'
const port = 8080

eez({
  env: environments.DEV,
  port: port,
  afterListen: () => {

    routing.get('/',(req, res) => {
      response.success(res, {data:'somedata'})
    })

    routing.post('/:test',(req,res) => {
      console.log(req.params.test)
      response.success(res, req.params)
    })
    
  }
})