Simple connect router
A simple connect middleware for rapidly creating pages
npm install connect connect-simple
Use the connect middleware like so...
var connect = require'connect';var simple = require'connect-simple';var app = connectuseroot: './www'listen3000;
In your app's root directory, create the file ./www/index.js
var ua = thisreqheaders'user-agent';thisresendua;
Start your app, and go to
http://localhost:3000, you should see your browser's user agent
You can add js files to the /www folder and you will be able to access them in your browser, for example
http://localhost:3000/test will resolve to
this.req will refer to the node.js request object.
There will also be a variable called
this.res which will refer to the node.js response object.
In some cases, there may be things that you will need access to in all your pages (for example, underscore), you can do this by importing them:
var connect = require'connect';var simple = require'connect-simple';var underscore = require'underscore';var app = connectuseroot: './www'imports:'_' : underscorelisten3000;
In this example, you will be able to access underscore from within your pages:
- Watch for files that have changed and then update the cache