Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ctl

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ctl

Controller module for NodeJS. Made to be extremely hackable and light!

  • 0.1.4
  • npm
  • Socket score

Version published
Weekly downloads
51
increased by1175%
Maintainers
1
Weekly downloads
 
Created
Source

NodeCTL

NodeCTL is an easy way to manage all those routes and ugly handlers in ExpressJS or some other library.

How it works

In the most basic usage, it would be something like this:

server.js

var express = require('express');
var app = express.createServer();
require('./controller.js').route(app);
app.listen(80);

controller.js

var host = require('ctl').ctl();
exports.route = function (server) {
	host.bind("/", function (page) {
		page.write("hello, world!");
	});
	host.serve(server);
}

Installation

npm install ctl

Please try it out! If you like it please say thank you. Or better, if you find bugs, have questions, or feedback, feel free to email me at me@leander.ca.

More Information

NodeCTL is really easy to use. The way it works is instead of the normal way of handling all this ugly stuff in req and res, that stuff is dealt with by a more civilized Request object that handles all of that for you (In the example, this object is passed in as page).

The details of the request object is listed below for your use and reference.

require('ctl').init([defaults]) - This function optionally takes defaults as values that are sent to the template engine for rendering (see render below).

defaults - Is a property holding the object you passed in with init().

headers() - Returns all of the headers from the client's request.

accepts(mimetype) - Checks to see if mimetype is in the accept part of the header.

set(key,val) - Sets the session variable key with value val.

get(key) - Gets the value of the session variable key.

param(name,default) - This is used to get the variables from GET, POST or from the URL. Example uses of this is shown in the examples folder.

redirect(url) - Pretty straightforward. Redirects (with status 302) to url.

json(obj) - Responds with obj as a json string and ends the request.

write(str) - Responds with str and ends the request.

render(tmpl,params) - Renders the template tmpl as you would in ExpressJS, passing in the parameters params to the template. Note that you can set some default parameters that will be sent along if they are not specified by render (of course, render can overwrite defaults).

Advanced Usage

FAQs

Package last updated on 14 Dec 2011

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc