Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 9.9KB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <div align="center">
  2. <img src="logo/horizontal.png" alt="connect logo" width="450px">
  3. [![NPM Version][npm-version-image]][npm-url]
  4. [![NPM Downloads][npm-downloads-image]][npm-url]
  5. [![Build Status][travis-image]][travis-url]
  6. [![Test Coverage][coveralls-image]][coveralls-url]
  7. </div>
  8. Connect is an extensible HTTP server framework for [node](http://nodejs.org) using "plugins" known as _middleware_.
  9. ```js
  10. var connect = require('connect');
  11. var http = require('http');
  12. var app = connect();
  13. // gzip/deflate outgoing responses
  14. var compression = require('compression');
  15. app.use(compression());
  16. // store session state in browser cookie
  17. var cookieSession = require('cookie-session');
  18. app.use(cookieSession({
  19. keys: ['secret1', 'secret2']
  20. }));
  21. // parse urlencoded request bodies into req.body
  22. var bodyParser = require('body-parser');
  23. app.use(bodyParser.urlencoded({extended: false}));
  24. // respond to all requests
  25. app.use(function(req, res){
  26. res.end('Hello from Connect!\n');
  27. });
  28. //create node.js http server and listen on port
  29. http.createServer(app).listen(3000);
  30. ```
  31. ## Getting Started
  32. Connect is a simple framework to glue together various "middleware" to handle requests.
  33. ### Install Connect
  34. ```sh
  35. $ npm install connect
  36. ```
  37. ### Create an app
  38. The main component is a Connect "app". This will store all the middleware
  39. added and is, itself, a function.
  40. ```js
  41. var app = connect();
  42. ```
  43. ### Use middleware
  44. The core of Connect is "using" middleware. Middleware are added as a "stack"
  45. where incoming requests will execute each middleware one-by-one until a middleware
  46. does not call `next()` within it.
  47. ```js
  48. app.use(function middleware1(req, res, next) {
  49. // middleware 1
  50. next();
  51. });
  52. app.use(function middleware2(req, res, next) {
  53. // middleware 2
  54. next();
  55. });
  56. ```
  57. ### Mount middleware
  58. The `.use()` method also takes an optional path string that is matched against
  59. the beginning of the incoming request URL. This allows for basic routing.
  60. ```js
  61. app.use('/foo', function fooMiddleware(req, res, next) {
  62. // req.url starts with "/foo"
  63. next();
  64. });
  65. app.use('/bar', function barMiddleware(req, res, next) {
  66. // req.url starts with "/bar"
  67. next();
  68. });
  69. ```
  70. ### Error middleware
  71. There are special cases of "error-handling" middleware. There are middleware
  72. where the function takes exactly 4 arguments. When a middleware passes an error
  73. to `next`, the app will proceed to look for the error middleware that was declared
  74. after that middleware and invoke it, skipping any error middleware above that
  75. middleware and any non-error middleware below.
  76. ```js
  77. // regular middleware
  78. app.use(function (req, res, next) {
  79. // i had an error
  80. next(new Error('boom!'));
  81. });
  82. // error middleware for errors that occurred in middleware
  83. // declared before this
  84. app.use(function onerror(err, req, res, next) {
  85. // an error occurred!
  86. });
  87. ```
  88. ### Create a server from the app
  89. The last step is to actually use the Connect app in a server. The `.listen()` method
  90. is a convenience to start a HTTP server (and is identical to the `http.Server`'s `listen`
  91. method in the version of Node.js you are running).
  92. ```js
  93. var server = app.listen(port);
  94. ```
  95. The app itself is really just a function with three arguments, so it can also be handed
  96. to `.createServer()` in Node.js.
  97. ```js
  98. var server = http.createServer(app);
  99. ```
  100. ## Middleware
  101. These middleware and libraries are officially supported by the Connect/Express team:
  102. - [body-parser](https://www.npmjs.com/package/body-parser) - previous `bodyParser`, `json`, and `urlencoded`. You may also be interested in:
  103. - [body](https://www.npmjs.com/package/body)
  104. - [co-body](https://www.npmjs.com/package/co-body)
  105. - [raw-body](https://www.npmjs.com/package/raw-body)
  106. - [compression](https://www.npmjs.com/package/compression) - previously `compress`
  107. - [connect-timeout](https://www.npmjs.com/package/connect-timeout) - previously `timeout`
  108. - [cookie-parser](https://www.npmjs.com/package/cookie-parser) - previously `cookieParser`
  109. - [cookie-session](https://www.npmjs.com/package/cookie-session) - previously `cookieSession`
  110. - [csurf](https://www.npmjs.com/package/csurf) - previously `csrf`
  111. - [errorhandler](https://www.npmjs.com/package/errorhandler) - previously `error-handler`
  112. - [express-session](https://www.npmjs.com/package/express-session) - previously `session`
  113. - [method-override](https://www.npmjs.com/package/method-override) - previously `method-override`
  114. - [morgan](https://www.npmjs.com/package/morgan) - previously `logger`
  115. - [response-time](https://www.npmjs.com/package/response-time) - previously `response-time`
  116. - [serve-favicon](https://www.npmjs.com/package/serve-favicon) - previously `favicon`
  117. - [serve-index](https://www.npmjs.com/package/serve-index) - previously `directory`
  118. - [serve-static](https://www.npmjs.com/package/serve-static) - previously `static`
  119. - [vhost](https://www.npmjs.com/package/vhost) - previously `vhost`
  120. Most of these are exact ports of their Connect 2.x equivalents. The primary exception is `cookie-session`.
  121. Some middleware previously included with Connect are no longer supported by the Connect/Express team, are replaced by an alternative module, or should be superseded by a better module. Use one of these alternatives instead:
  122. - `cookieParser`
  123. - [cookies](https://www.npmjs.com/package/cookies) and [keygrip](https://www.npmjs.com/package/keygrip)
  124. - `limit`
  125. - [raw-body](https://www.npmjs.com/package/raw-body)
  126. - `multipart`
  127. - [connect-multiparty](https://www.npmjs.com/package/connect-multiparty)
  128. - [connect-busboy](https://www.npmjs.com/package/connect-busboy)
  129. - `query`
  130. - [qs](https://www.npmjs.com/package/qs)
  131. - `staticCache`
  132. - [st](https://www.npmjs.com/package/st)
  133. - [connect-static](https://www.npmjs.com/package/connect-static)
  134. Checkout [http-framework](https://github.com/Raynos/http-framework/wiki/Modules) for many other compatible middleware!
  135. ## API
  136. The Connect API is very minimalist, enough to create an app and add a chain
  137. of middleware.
  138. When the `connect` module is required, a function is returned that will construct
  139. a new app when called.
  140. ```js
  141. // require module
  142. var connect = require('connect')
  143. // create app
  144. var app = connect()
  145. ```
  146. ### app(req, res[, next])
  147. The `app` itself is a function. This is just an alias to `app.handle`.
  148. ### app.handle(req, res[, out])
  149. Calling the function will run the middleware stack against the given Node.js
  150. http request (`req`) and response (`res`) objects. An optional function `out`
  151. can be provided that will be called if the request (or error) was not handled
  152. by the middleware stack.
  153. ### app.listen([...])
  154. Start the app listening for requests. This method will internally create a Node.js
  155. HTTP server and call `.listen()` on it.
  156. This is an alias to the `server.listen()` method in the version of Node.js running,
  157. so consult the Node.js documentation for all the different variations. The most
  158. common signature is [`app.listen(port)`](https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_server_listen_port_hostname_backlog_callback).
  159. ### app.use(fn)
  160. Use a function on the app, where the function represents a middleware. The function
  161. will be invoked for every request in the order that `app.use` is called. The function
  162. is called with three arguments:
  163. ```js
  164. app.use(function (req, res, next) {
  165. // req is the Node.js http request object
  166. // res is the Node.js http response object
  167. // next is a function to call to invoke the next middleware
  168. })
  169. ```
  170. In addition to a plan function, the `fn` argument can also be a Node.js HTTP server
  171. instance or another Connect app instance.
  172. ### app.use(route, fn)
  173. Use a function on the app, where the function represents a middleware. The function
  174. will be invoked for every request in which the URL (`req.url` property) starts with
  175. the given `route` string in the order that `app.use` is called. The function is
  176. called with three arguments:
  177. ```js
  178. app.use('/foo', function (req, res, next) {
  179. // req is the Node.js http request object
  180. // res is the Node.js http response object
  181. // next is a function to call to invoke the next middleware
  182. })
  183. ```
  184. In addition to a plan function, the `fn` argument can also be a Node.js HTTP server
  185. instance or another Connect app instance.
  186. The `route` is always terminated at a path separator (`/`) or a dot (`.`) character.
  187. This means the given routes `/foo/` and `/foo` are the same and both will match requests
  188. with the URLs `/foo`, `/foo/`, `/foo/bar`, and `/foo.bar`, but not match a request with
  189. the URL `/foobar`.
  190. The `route` is matched in a case-insensitive manor.
  191. In order to make middleware easier to write to be agnostic of the `route`, when the
  192. `fn` is invoked, the `req.url` will be altered to remove the `route` part (and the
  193. original will be available as `req.originalUrl`). For example, if `fn` is used at the
  194. route `/foo`, the request for `/foo/bar` will invoke `fn` with `req.url === '/bar'`
  195. and `req.originalUrl === '/foo/bar'`.
  196. ## Running Tests
  197. ```bash
  198. npm install
  199. npm test
  200. ```
  201. ## People
  202. The Connect project would not be the same without all the people involved.
  203. The original author of Connect is [TJ Holowaychuk](https://github.com/tj)
  204. The current lead maintainer is [Douglas Christopher Wilson](https://github.com/dougwilson)
  205. [List of all contributors](https://github.com/senchalabs/connect/graphs/contributors)
  206. ## Node Compatibility
  207. - Connect `< 1.x` - node `0.2`
  208. - Connect `1.x` - node `0.4`
  209. - Connect `< 2.8` - node `0.6`
  210. - Connect `>= 2.8 < 3` - node `0.8`
  211. - Connect `>= 3` - node `0.10`, `0.12`, `4.x`, `5.x`, `6.x`, `7.x`, `8.x`, `9.x`, `10.x`, `11.x`, `12.x`; io.js `1.x`, `2.x`, `3.x`
  212. ## License
  213. [MIT](LICENSE)
  214. [coveralls-image]: https://badgen.net/coveralls/c/github/senchalabs/connect/master
  215. [coveralls-url]: https://coveralls.io/r/senchalabs/connect?branch=master
  216. [npm-downloads-image]: https://badgen.net/npm/dm/connect
  217. [npm-url]: https://npmjs.org/package/connect
  218. [npm-version-image]: https://badgen.net/npm/v/connect
  219. [travis-image]: https://badgen.net/travis/senchalabs/connect/master
  220. [travis-url]: https://travis-ci.org/senchalabs/connect