7 var express = require('../..');
8 var logger = require('morgan');
9 var path = require('path');
13 app.use(logger('dev'));
15 // express on its own has no notion
16 // of a "file". The express.static()
17 // middleware checks for a file matching
18 // the `req.path` within the directory
19 // that you pass it. In this case "GET /js/app.js"
20 // will look for "./public/js/app.js".
22 app.use(express.static(path.join(__dirname, 'public')));
24 // if you wanted to "prefix" you may use
25 // the mounting feature of Connect, for example
26 // "GET /static/js/app.js" instead of "GET /js/app.js".
27 // The mount-path "/static" is simply removed before
28 // passing control to the express.static() middleware,
29 // thus it serves the file correctly by ignoring "/static"
30 app.use('/static', express.static(path.join(__dirname, 'public')));
32 // if for some reason you want to serve files from
33 // several directories, you can use express.static()
34 // multiple times! Here we're passing "./public/css",
35 // this will allow "GET /style.css" instead of "GET /css/style.css":
36 app.use(express.static(path.join(__dirname, 'public', 'css')));
39 console.log('listening on port 3000');
41 console.log(' GET /hello.txt');
42 console.log(' GET /js/app.js');
43 console.log(' GET /css/style.css');