New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

courser

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

courser

Route manager for express web framework

latest
npmnpm
Version
0.0.7
Version published
Maintainers
1
Created
Source

courser

Courser is a route manager for express web framework, provides an easy way to manage routes.

Installation

Using NPM to install Courser module directly:

npm install courser

Example

A small example of managing routes for express:

<Working Directory>/app.js

var express = require('express');
var Courser = require('courser');

var app = express.createServer();

app.configure(function() {
  app.set('views', __dirname + '/views');
	app.set('view engine', 'jade');
});

// Loading and Initializing Routes from specific path
var courser = new Courser(app);
courser.addPath(__dirname + '/routes');
courser.init(function() {
	app.listen(3000);
});

<Working Directory>/routes/default.js

module.exports = {
  '/': index,
  '/hello': hello
};

function index(req, res) {

	res.render('index', { title: 'Courser Example' });
};

function hello(req, res, next) {

  res.render('hello', { title: 'Hello' });
};

<Working Directory>/routes/other.js

module.exports = {
  '/other': other
};

function other(req, res) {

  res.render('other', { title: 'Courser Example Two' });
};

All of JavaScript files(*.js) in specific path will be loaded by Courser. Developer can add more APIs or pages to existing files or new file.

Example of Using Middleware:

module.exports = {
    '/middleware': [
		DoSomethingBeforeHandler,
		middleware
	]
};

function DoSomethingBeforeHandler(req, res, next) {

	console.log('Do Something');

	next();
};

function middleware(req, res) {

	res.render('index', { title: 'Courser Example' });
};

Example of Specifying HTTP Method:

module.exports = {
    '/method': {
		get: get,
		post: post
	}
};

function get(req, res) {

	res.end('GET Method');
};

function post(req, res) {

	res.end('POST Method');
};

License

Licensed under the MIT License

Authors

Copyright© 2012 Fred Chien <fred@mandice.com>

Keywords

web

FAQs

Package last updated on 05 Dec 2013

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