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

@znci/kelp

v3.2.1

Published

An easy to use, customizable ExpressJS web server.

Downloads

44

Readme

Kelp

CodeFactor npm version

An easy to use, customizable ExpressJS web server.

Features

  • File-based routing
  • Built-in view engines
  • Disabled routes
  • Development only routes
  • Static file serving
  • Automatic bodyParser.json, bodyParser.urlencoded, and cookieParser middlewaresetup
  • Logging
  • Customizable 404 handler
  • Customizable error handler

Basic Usage

Install the package: npm i @znci/kelp

import express from "express";
import kelpify from "@znci/kelp";

const app = express();
kelpify(app, {
  // options go here
});

Place your route files in the configured routes directory (routes) by default and follow the format under the Routes section.

Kelp will automagically setup and serve your application on port 3000 by default (can be turned off).

Options

| Option | Description | Default | Extra | Type | | ----------------- | ------------------------------------------------ | ----------------------- | ------------------------------------------------------- | ----------------- | | routesDirectory | The directory to look for routes in | __dirname + "/routes" | | String | | publicDirectory | The directory to serve static files from | __dirname + "/public" | | String | | viewsDirectory | The directory to look for views in | __dirname + "/views" | | String | | viewEngine | The view engine to use | "none" | valid: "none", "ejs", "pug", "nunjucks", "handlebars" | String | | notFoundHandler | The middleware function to use for 404 errors | Function | | Callback Function | | errorHandler | The middleware function to use for errors | Function | | Callback Function | | port | The port to serve your application on | 3000 | | Int | | environment | The environment to run your application in | "development" | valid: "development", "production" | String | | autostart | Whether or not to automatically start the server | false | | Boolean |

All options have default values, so none of them strictly need to be configured.

What is the environment for?

The environment option is used to determine whether or not to use development only routes and more verbose logging. If the environment is set to "production", then development only routes will not be used and logging will be less verbose. If the environment is set to "development", then development only routes will be used and logging will be more verbose.

Autostart Disabled

kelpify is an async function. If you have autostart disabled, you will have to write your own async IIFE or .then() chain to start the server.

import express from "express";
import kelpify from "@znci/kelp";

const app = express();

(async () => {
  await kelpify(app, {
    autostart: false,
  });

  app.listen(3000);
})();

OR

import express from "express";
import kelpify from "@znci/kelp";

const app = express();
kelpify(app, {
  autostart: false,
}).then(() => {
  app.listen(3000);
});

Routes

Routes in kelp are very simple and follow a straightforward format.

export default {
  path: "/",
  method: "GET",
  disabled: false,
  developmentRoute: false,

  handler: (req, res) => {
    // your handler code here
  },
};

There must be only be 1 route per file. Route paths do not strictly have to match the file name/path but it is reccomended for maintainability.

Notes

  • Kelp v3 is still in early development. Please report any bugs you find.
  • Kelp uses the express-handlebars package by default for Handlebars support. Do note that this package requires you to use the .handlebars extension. The package also requires (views directory)/layouts/main.handlebars to exist and contain {{{body}}} somewhere.
  • The nunjucks library requires that calls to res.render() include the file extension of the template you are trying to render.

Documentation

Full documentation for Kelp will be coming soon.