...**/!(*.map|*.min.js)Size
Gzip
Dependencies
Publish
Install
Publish
Install
@@ -1,8 +1,6 @@ | |||
| 1 | (The MIT License) | 1 | (The MIT License) |
| 2 | 2 | ||
| 3 | Copyright (c) 2009-2013 TJ Holowaychuk <tj@vision-media.ca> | ||
| 4 | Copyright (c) 2013 Roman Shtylman <shtylman+expressjs@gmail.com> | ||
| 5 | Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com> | 3 | Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca> |
| 6 | 4 | ||
| 7 | Permission is hereby granted, free of charge, to any person obtaining | 5 | Permission is hereby granted, free of charge, to any person obtaining |
| 8 | a copy of this software and associated documentation files (the | 6 | a copy of this software and associated documentation files (the |
@@ -21,4 +19,4 @@ | |||
| 21 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 23 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 24 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -2,10 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | Fast, unopinionated, minimalist web framework for [node](http://nodejs.org). | 3 | Fast, unopinionated, minimalist web framework for [node](http://nodejs.org). |
| 4 | 4 | ||
| 5 | [](https://www.npmjs.org/package/express) | ||
| 6 | [](https://travis-ci.org/strongloop/express) | ||
| 7 | [](https://coveralls.io/r/strongloop/express) | ||
| 8 | [](https://gratipay.com/dougwilson/) | 5 | [](https://travis-ci.org/visionmedia/express) [](https://www.gittip.com/visionmedia/) |
| 9 | 6 | ||
| 10 | ```js | 7 | ```js |
| 11 | var express = require('express'); | 8 | var express = require('express'); |
@@ -18,17 +15,24 @@ | |||
| 18 | app.listen(3000); | 15 | app.listen(3000); |
| 19 | ``` | 16 | ``` |
| 20 | 17 | ||
| 18 | Note that Express v4 release candidates have been released. | ||
| 19 | Please try it out, but not in production, and report any issues you may find here or to the appropriate repositories. | ||
| 20 | Be sure to read [Migrating from 3.x to 4.x](https://github.com/visionmedia/express/wiki/Migrating-from-3.x-to-4.x) as well as [New features in 4.x](https://github.com/visionmedia/express/wiki/New-features-in-4.x). | ||
| 21 | |||
| 21 | ## Installation | 22 | ## Installation |
| 22 | 23 | ||
| 23 | $ npm install -g express | 24 | $ npm install express |
| 24 | 25 | ||
| 25 | ## Quick Start | 26 | ## Quick Start |
| 26 | 27 | ||
| 27 | The quickest way to get started with express is to utilize the executable `express(1)` to generate an application as shown below: | 28 | The quickest way to get started with express is to utilize the executable [`express(1)`](http://github.com/expressjs/generator) to generate an application as shown below: |
| 29 | |||
| 30 | Install the executable. The executable's major version will match Express's: | ||
| 31 | |||
| 32 | $ npm install -g express-generator@3 | ||
| 28 | 33 | ||
| 29 | Create the app: | 34 | Create the app: |
| 30 | 35 | ||
| 31 | $ npm install -g express | ||
| 32 | $ express /tmp/foo && cd /tmp/foo | 36 | $ express /tmp/foo && cd /tmp/foo |
| 33 | 37 | ||
| 34 | Install dependencies: | 38 | Install dependencies: |
@@ -37,11 +41,10 @@ | |||
| 37 | 41 | ||
| 38 | Start the server: | 42 | Start the server: |
| 39 | 43 | ||
| 40 | $ node app | 44 | $ npm start |
| 41 | 45 | ||
| 42 | ## Features | 46 | ## Features |
| 43 | 47 | ||
| 44 | * Built on [Connect](http://github.com/senchalabs/connect) | ||
| 45 | * Robust routing | 48 | * Robust routing |
| 46 | * HTTP helpers (redirection, caching, etc) | 49 | * HTTP helpers (redirection, caching, etc) |
| 47 | * View system supporting 14+ template engines | 50 | * View system supporting 14+ template engines |
@@ -57,19 +60,17 @@ | |||
| 57 | it a great solution for single page applications, web sites, hybrids, or public | 60 | it a great solution for single page applications, web sites, hybrids, or public |
| 58 | HTTP APIs. | 61 | HTTP APIs. |
| 59 | 62 | ||
| 60 | Built on Connect, you can use _only_ what you need, and nothing more. Applications | ||
| 61 | can be as big or as small as you like, even a single file. Express does | ||
| 62 | not force you to use any specific ORM or template engine. With support for over | 63 | Express does not force you to use any specific ORM or template engine. With support for over |
| 63 | 14 template engines via [Consolidate.js](http://github.com/visionmedia/consolidate.js), | 64 | 14 template engines via [Consolidate.js](http://github.com/visionmedia/consolidate.js), |
| 64 | you can quickly craft your perfect framework. | 65 | you can quickly craft your perfect framework. |
| 65 | 66 | ||
| 66 | ## More Information | 67 | ## More Information |
| 67 | 68 | ||
| 68 | * [Website and Documentation](http://expressjs.com/) stored at [strongloop/expressjs.com](https://github.com/strongloop/expressjs.com) | 69 | * [Website and Documentation](http://expressjs.com/) stored at [visionmedia/expressjs.com](https://github.com/visionmedia/expressjs.com) |
| 69 | * Join #express on freenode | 70 | * Join #express on freenode |
| 70 | * [Google Group](http://groups.google.com/group/express-js) for discussion | 71 | * [Google Group](http://groups.google.com/group/express-js) for discussion |
| 71 | * Follow [tjholowaychuk](http://twitter.com/tjholowaychuk) on twitter for updates | ||
| 72 | * Visit the [Wiki](http://github.com/strongloop/express/wiki) | 72 | * Follow [tjholowaychuk](http://twitter.com/tjholowaychuk) and [defunctzombie](https://twitter.com/defunctzombie) on twitter for updates |
| 73 | * Visit the [Wiki](http://github.com/visionmedia/express/wiki) | ||
| 73 | * [Русскоязычная документация](http://jsman.ru/express/) | 74 | * [Русскоязычная документация](http://jsman.ru/express/) |
| 74 | * Run express examples [online](https://runnable.com/express) | 75 | * Run express examples [online](https://runnable.com/express) |
| 75 | 76 | ||
@@ -77,7 +78,7 @@ | |||
| 77 | 78 | ||
| 78 | Clone the Express repo, then install the dev dependencies to install all the example / test suite dependencies: | 79 | Clone the Express repo, then install the dev dependencies to install all the example / test suite dependencies: |
| 79 | 80 | ||
| 80 | $ git clone git://github.com/strongloop/express.git --depth 1 | 81 | $ git clone git://github.com/visionmedia/express.git --depth 1 |
| 81 | $ cd express | 82 | $ cd express |
| 82 | $ npm install | 83 | $ npm install |
| 83 | 84 | ||
@@ -97,35 +98,12 @@ | |||
| 97 | 98 | ||
| 98 | Then run the tests: | 99 | Then run the tests: |
| 99 | 100 | ||
| 100 | ```sh | ||
| 101 | $ npm test | ||
| 102 | ``` | 101 | $ make test |
| 103 | 102 | ||
| 104 | ## Contributors | 103 | ## Contributors |
| 105 | 104 | ||
| 106 | https://github.com/strongloop/express/graphs/contributors | 105 | https://github.com/visionmedia/express/graphs/contributors |
| 107 | 106 | ||
| 108 | ## License | 107 | ## License |
| 109 | 108 | ||
| 110 | (The MIT License) | ||
| 111 | |||
| 112 | Copyright (c) 2009-2012 TJ Holowaychuk <tj@vision-media.ca> | ||
| 113 | |||
| 114 | Permission is hereby granted, free of charge, to any person obtaining | ||
| 115 | a copy of this software and associated documentation files (the | ||
| 116 | 'Software'), to deal in the Software without restriction, including | ||
| 117 | without limitation the rights to use, copy, modify, merge, publish, | ||
| 118 | distribute, sublicense, and/or sell copies of the Software, and to | ||
| 119 | permit persons to whom the Software is furnished to do so, subject to | ||
| 120 | the following conditions: | ||
| 121 | |||
| 122 | The above copyright notice and this permission notice shall be | ||
| 123 | included in all copies or substantial portions of the Software. | ||
| 124 | |||
| 125 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
| 126 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 127 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 128 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| 129 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| 130 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| 131 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 109 | MIT |
@@ -2,15 +2,13 @@ | |||
| 2 | * Module dependencies. | 2 | * Module dependencies. |
| 3 | */ | 3 | */ |
| 4 | 4 | ||
| 5 | var deprecate = require('depd')('express'); | ||
| 6 | var mixin = require('merge-descriptors'); | ||
| 7 | var merge = require('utils-merge'); | ||
| 8 | var connect = require('connect') | ||
| 9 | , proto = require('./application') | ||
| 10 | , Route = require('./router/route') | ||
| 11 | , Router = require('./router') | ||
| 12 | , req = require('./request') | ||
| 13 | , res = require('./response'); | 5 | var EventEmitter = require('events').EventEmitter; |
| 6 | var mixin = require('utils-merge'); | ||
| 7 | var proto = require('./application'); | ||
| 8 | var Route = require('./router/route'); | ||
| 9 | var Router = require('./router'); | ||
| 10 | var req = require('./request'); | ||
| 11 | var res = require('./response'); | ||
| 14 | 12 | ||
| 15 | /** | 13 | /** |
| 16 | * Expose `createApplication()`. | 14 | * Expose `createApplication()`. |
@@ -19,12 +17,6 @@ | |||
| 19 | exports = module.exports = createApplication; | 17 | exports = module.exports = createApplication; |
| 20 | 18 | ||
| 21 | /** | 19 | /** |
| 22 | * Expose mime. | ||
| 23 | */ | ||
| 24 | |||
| 25 | exports.mime = connect.mime; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * Create an express application. | 20 | * Create an express application. |
| 29 | * | 21 | * |
| 30 | * @return {Function} | 22 | * @return {Function} |
@@ -32,8 +24,13 @@ | |||
| 32 | */ | 24 | */ |
| 33 | 25 | ||
| 34 | function createApplication() { | 26 | function createApplication() { |
| 35 | var app = connect(); | ||
| 36 | merge(app, proto); | 27 | var app = function(req, res, next) { |
| 28 | app.handle(req, res, next); | ||
| 29 | }; | ||
| 30 | |||
| 31 | mixin(app, proto); | ||
| 32 | mixin(app, EventEmitter.prototype); | ||
| 33 | |||
| 37 | app.request = { __proto__: req, app: app }; | 34 | app.request = { __proto__: req, app: app }; |
| 38 | app.response = { __proto__: res, app: app }; | 35 | app.response = { __proto__: res, app: app }; |
| 39 | app.init(); | 36 | app.init(); |
@@ -41,27 +38,6 @@ | |||
| 41 | } | 38 | } |
| 42 | 39 | ||
| 43 | /** | 40 | /** |
| 44 | * Expose connect.middleware as express.* | ||
| 45 | * for example `express.logger` etc. | ||
| 46 | */ | ||
| 47 | |||
| 48 | mixin(exports, connect.middleware); | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Deprecated createServer(). | ||
| 52 | */ | ||
| 53 | |||
| 54 | exports.createServer = deprecate.function(createApplication, | ||
| 55 | 'createServer() is deprecated\n' + | ||
| 56 | 'express applications no longer inherit from http.Server\n' + | ||
| 57 | 'please use:\n' + | ||
| 58 | '\n' + | ||
| 59 | ' var express = require("express");\n' + | ||
| 60 | ' var app = express();\n' + | ||
| 61 | '\n' | ||
| 62 | ); | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Expose the prototypes. | 41 | * Expose the prototypes. |
| 66 | */ | 42 | */ |
| 67 | 43 | ||
@@ -76,7 +52,41 @@ | |||
| 76 | exports.Route = Route; | 52 | exports.Route = Route; |
| 77 | exports.Router = Router; | 53 | exports.Router = Router; |
| 78 | 54 | ||
| 79 | // Error handler title | 55 | /** |
| 56 | * Expose middleware | ||
| 57 | */ | ||
| 80 | 58 | ||
| 81 | exports.errorHandler.title = 'Express'; | 59 | exports.query = require('./middleware/query'); |
| 60 | exports.static = require('serve-static'); | ||
| 82 | 61 | ||
| 62 | /** | ||
| 63 | * Replace removed middleware with an appropriate error message. | ||
| 64 | */ | ||
| 65 | |||
| 66 | [ | ||
| 67 | 'json', | ||
| 68 | 'urlencoded', | ||
| 69 | 'bodyParser', | ||
| 70 | 'compress', | ||
| 71 | 'cookieSession', | ||
| 72 | 'session', | ||
| 73 | 'logger', | ||
| 74 | 'cookieParser', | ||
| 75 | 'favicon', | ||
| 76 | 'responseTime', | ||
| 77 | 'errorHandler', | ||
| 78 | 'timeout', | ||
| 79 | 'methodOverride', | ||
| 80 | 'vhost', | ||
| 81 | 'csrf', | ||
| 82 | 'directory', | ||
| 83 | 'limit', | ||
| 84 | 'multipart', | ||
| 85 | 'staticCache', | ||
| 86 | ].forEach(function (name) { | ||
| 87 | Object.defineProperty(exports, name, { | ||
| 88 | get: function () { | ||
| 89 | throw new Error('Most middleware (like ' + name + ') is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.'); | ||
| 90 | } | ||
| 91 | }); | ||
| 92 | }); | ||
@@ -2,14 +2,14 @@ | |||
| 2 | * Module dependencies. | 2 | * Module dependencies. |
| 3 | */ | 3 | */ |
| 4 | 4 | ||
| 5 | var path = require('path') | ||
| 6 | , fs = require('fs') | ||
| 7 | , utils = require('./utils') | ||
| 8 | , dirname = path.dirname | ||
| 9 | , basename = path.basename | ||
| 10 | , extname = path.extname | ||
| 11 | , exists = fs.existsSync || path.existsSync | ||
| 12 | , join = path.join; | 5 | var path = require('path'); |
| 6 | var fs = require('fs'); | ||
| 7 | var utils = require('./utils'); | ||
| 8 | var dirname = path.dirname; | ||
| 9 | var basename = path.basename; | ||
| 10 | var extname = path.extname; | ||
| 11 | var exists = fs.existsSync || path.existsSync; | ||
| 12 | var join = path.join; | ||
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| 15 | * Expose `View`. | 15 | * Expose `View`. |
@@ -0,0 +1,34 @@ | |
| 1 | |
| 2 | MOCHA_OPTS= --check-leaks |
| 3 | REPORTER = dot |
| 4 | |
| 5 | check: test |
| 6 | |
| 7 | test: test-unit test-acceptance |
| 8 | |
| 9 | test-unit: |
| 10 | @NODE_ENV=test ./node_modules/.bin/mocha \ |
| 11 | --reporter $(REPORTER) \ |
| 12 | --globals setImmediate,clearImmediate \ |
| 13 | $(MOCHA_OPTS) |
| 14 | |
| 15 | test-acceptance: |
| 16 | @NODE_ENV=test ./node_modules/.bin/mocha \ |
| 17 | --reporter $(REPORTER) \ |
| 18 | --bail \ |
| 19 | test/acceptance/*.js |
| 20 | |
| 21 | test-cov: lib-cov |
| 22 | @EXPRESS_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html |
| 23 | |
| 24 | lib-cov: |
| 25 | @jscoverage lib lib-cov |
| 26 | |
| 27 | bench: |
| 28 | @$(MAKE) -C benchmarks |
| 29 | |
| 30 | clean: |
| 31 | rm -f coverage.html |
| 32 | rm -fr lib-cov |
| 33 | |
| 34 | .PHONY: test test-unit test-acceptance bench clean |
@@ -0,0 +1,26 @@ | |
| 1 | /** |
| 2 | * Initialization middleware, exposing the |
| 3 | * request and response to eachother, as well |
| 4 | * as defaulting the X-Powered-By header field. |
| 5 | * |
| 6 | * @param {Function} app |
| 7 | * @return {Function} |
| 8 | * @api private |
| 9 | */ |
| 10 | |
| 11 | exports.init = function(app){ |
| 12 | return function expressInit(req, res, next){ |
| 13 | if (app.enabled('x-powered-by')) res.setHeader('X-Powered-By', 'Express'); |
| 14 | req.res = res; |
| 15 | res.req = req; |
| 16 | req.next = next; |
| 17 | |
| 18 | req.__proto__ = app.request; |
| 19 | res.__proto__ = app.response; |
| 20 | |
| 21 | res.locals = res.locals || Object.create(null); |
| 22 | |
| 23 | next(); |
| 24 | }; |
| 25 | }; |
| 26 | |
@@ -0,0 +1,39 @@ | |
| 1 | /** |
| 2 | * Module dependencies. |
| 3 | */ |
| 4 | |
| 5 | var qs = require('qs'); |
| 6 | var parseUrl = require('parseurl'); |
| 7 | |
| 8 | /** |
| 9 | * Query: |
| 10 | * |
| 11 | * Automatically parse the query-string when available, |
| 12 | * populating the `req.query` object using |
| 13 | * [qs](https://github.com/visionmedia/node-querystring). |
| 14 | * |
| 15 | * Examples: |
| 16 | * |
| 17 | * .use(connect.query()) |
| 18 | * .use(function(req, res){ |
| 19 | * res.end(JSON.stringify(req.query)); |
| 20 | * }); |
| 21 | * |
| 22 | * The `options` passed are provided to qs.parse function. |
| 23 | * |
| 24 | * @param {Object} options |
| 25 | * @return {Function} |
| 26 | * @api public |
| 27 | */ |
| 28 | |
| 29 | module.exports = function query(options){ |
| 30 | return function query(req, res, next){ |
| 31 | if (!req.query) { |
| 32 | req.query = ~req.url.indexOf('?') |
| 33 | ? qs.parse(parseUrl(req).query, options) |
| 34 | : {}; |
| 35 | } |
| 36 | |
| 37 | next(); |
| 38 | }; |
| 39 | }; |
@@ -0,0 +1,67 @@ | |
| 1 | /** |
| 2 | * Module dependencies. |
| 3 | */ |
| 4 | |
| 5 | var pathRegexp = require('path-to-regexp'); |
| 6 | var debug = require('debug')('express:router:layer'); |
| 7 | |
| 8 | /** |
| 9 | * Expose `Layer`. |
| 10 | */ |
| 11 | |
| 12 | module.exports = Layer; |
| 13 | |
| 14 | function Layer(path, options, fn) { |
| 15 | if (!(this instanceof Layer)) { |
| 16 | return new Layer(path, options, fn); |
| 17 | } |
| 18 | |
| 19 | debug('new %s', path); |
| 20 | options = options || {}; |
| 21 | this.regexp = pathRegexp(path, this.keys = [], options); |
| 22 | this.handle = fn; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Check if this route matches `path`, if so |
| 27 | * populate `.params`. |
| 28 | * |
| 29 | * @param {String} path |
| 30 | * @return {Boolean} |
| 31 | * @api private |
| 32 | */ |
| 33 | |
| 34 | Layer.prototype.match = function(path){ |
| 35 | var keys = this.keys; |
| 36 | var params = this.params = {}; |
| 37 | var m = this.regexp.exec(path); |
| 38 | var n = 0; |
| 39 | var key; |
| 40 | var val; |
| 41 | |
| 42 | if (!m) return false; |
| 43 | |
| 44 | this.path = m[0]; |
| 45 | |
| 46 | for (var i = 1, len = m.length; i < len; ++i) { |
| 47 | key = keys[i - 1]; |
| 48 | |
| 49 | try { |
| 50 | val = 'string' == typeof m[i] |
| 51 | ? decodeURIComponent(m[i]) |
| 52 | : m[i]; |
| 53 | } catch(e) { |
| 54 | var err = new Error("Failed to decode param '" + m[i] + "'"); |
| 55 | err.status = 400; |
| 56 | throw err; |
| 57 | } |
| 58 | |
| 59 | if (key) { |
| 60 | params[key.name] = val; |
| 61 | } else { |
| 62 | params[n++] = val; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return true; |
| 67 | }; |
@@ -0,0 +1,23 @@ | |
| 1 | |
| 2 | var http = require('http'); |
| 3 | var express = require('..'); |
| 4 | var app = express(); |
| 5 | |
| 6 | // number of middleware |
| 7 | |
| 8 | var n = parseInt(process.env.MW || '1', 10); |
| 9 | console.log(' %s middleware', n); |
| 10 | |
| 11 | while (n--) { |
| 12 | app.use(function(req, res, next){ |
| 13 | next(); |
| 14 | }); |
| 15 | } |
| 16 | |
| 17 | var body = new Buffer('Hello World'); |
| 18 | |
| 19 | app.use(function(req, res, next){ |
| 20 | res.send(body); |
| 21 | }); |
| 22 | |
| 23 | app.listen(3333); |