
Security News
Node.js Homepage Adds Paid Support Link, Prompting Contributor Pushback
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
ctl
is a lightweight framework to manage code for node servers. Tried and tested in production.
yarn add ctl
You can run a server simply with
PORT=8001 node -e 'require("ctl").init()'
Or for more complex settings, index.js
:
require('ctl').init(opts) // options optional, see below for full doc
In config.js
:
module.exports = async () => {
return {
message: 'hello world',
}
};
In src/lifecycle/startup.js
:
const ctl = require('ctl');
const config = ctl.config();
const log = ctl.log('startup');
module.exports = async (app) => {
// app.get() ... setup routes
log.debug('Loaded config:', config.message); // => Loaded config: hello world
};
const stage = ctl.stage();
const config = ctl.config();
const log = ctl.log('section');
Most servers need an environment flag, like local
, staging
or prod
. You can do this easily by setting the STAGE
environment variable, and running the server like STAGE=local node index.js
. This will then be read into ctl.stage().
Config also works out of the box, and ctl will look from a variety of places and merge the configs. Here are all the places it will look:
Note: ROOT is the home directory, and SRC is the src directory (defaults to /src), see in options
As you can see, it will load the right config in based on the STAGE you set.
Please refer to the documentation for better-logs
Lifecycles are events you can implement to run at different stages of the server starting. You can put them in src/lifecycle
folder, like src/lifecycle/after.js
, or you can set in these as async functions and pass it in to the options or from the config.
Here are the valid options you can pass to init
:
By default, ctl comes with an express server so you can get started quickly. It uses nunjucks and can host static files, and you can expand on it further in the startup
part of your lifecycle before the server begins listening.
You can also write your own service, it's really easy. A service is just an object with two functions, create(ctl)
and run(app, ctl)
. You can pass this to the options in init
or define it in the config.
run
.The first version of ctl, way back in 2010, was built primarily as a way to manage controllers and handle server requests consistently. But with the advent of async
/await
, it's much easier to write logic nowadays. The goal of ctl, as it has always been, is to reduce the amount of time it takes you to get up and running with a full on, system that's ready to scale. That way you focus on building the project and validating the idea, and not on inconsequential things like how to structure your code/server.
Feel free to use this for whatever you like, but don't blame me if someone loses an eye.
If you are using this, I'd love to hear about your project. It's great to know my code is being used somewhere by someone.
FAQs
Controller module for NodeJS. Made to be extremely hackable and light!
The npm package ctl receives a total of 16 weekly downloads. As such, ctl popularity was classified as not popular.
We found that ctl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.
Research
Security News
The Socket Research Team investigates a malicious Python typosquat of a popular password library that forces Windows shutdowns when input is incorrect.