package.yash => README.md
[webi-installers/.git] / node / README.md
1 ---
2 title: Node.js
3 homepage: https://nodejs.org
4 tagline: |
5   Node.jsĀ® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
6 description: |
7   Node is great for simple, snappy HTTP(S) servers, and for stitching APIs together with minimal fuss or muss.
8 ---
9
10 Hello World
11
12 ```bash
13 node -e 'console.log("Hello, World!")'
14 > Hello, World!
15 ```
16
17 A Simple Web Server
18
19 `server.js`:
20
21 ```bash
22 var http = require('http');
23 var app = function (req, res) {
24   res.end('Hello, World!');
25 };
26 http.createServer(app).listen(8080, function () {
27   console.info('Listening on', this.address());
28 });
29 ```
30
31 ```bash
32 node server.js
33 ```
34
35 An Express App
36
37 ```bash
38 mkdir my-server
39 pushd my-server
40 npm init
41 npm install --save express
42 ```
43
44 `app.js`:
45
46 ```js
47 'use strict';
48
49 var express = require('express');
50 var app = express();
51
52 app.use('/', function (req, res, next) {
53   res.end("Hello, World!");
54 });
55
56 module.exports = app;</code></pre>
57 ```
58
59 `server.js`:
60
61 ```js
62 'use strict';
63
64 var http = require('http');
65 var app = require('./app.js');
66
67 http.createServer(app).listen(8080, function () {
68   console.info('Listening on', this.address());
69 });
70 ```
71
72 ```bash
73 npm start
74 ```