3.2.1 • Published 5 months ago

@znci/kelp v3.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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

OptionDescriptionDefaultExtraType
routesDirectoryThe directory to look for routes in__dirname + "/routes"String
publicDirectoryThe directory to serve static files from__dirname + "/public"String
viewsDirectoryThe directory to look for views in__dirname + "/views"String
viewEngineThe view engine to use"none"valid: "none", "ejs", "pug", "nunjucks", "handlebars"String
notFoundHandlerThe middleware function to use for 404 errorsFunctionCallback Function
errorHandlerThe middleware function to use for errorsFunctionCallback Function
portThe port to serve your application on3000Int
environmentThe environment to run your application in"development"valid: "development", "production"String
autostartWhether or not to automatically start the serverfalseBoolean

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.

3.1.3

9 months ago

3.2.1

5 months ago

3.1.2

9 months ago

3.2.0

5 months ago

3.1.1

9 months ago

3.1.0

9 months ago

3.0.1

9 months ago

2.0.2-alpha

9 months ago

3.0.0

9 months ago

3.2.0-beta1

9 months ago

2.0.1-alpha

9 months ago

2.0.0-alpha

9 months ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.1

1 year ago