mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-03-03 18:00:18 +00:00
75 lines
1.1 KiB
Markdown
75 lines
1.1 KiB
Markdown
---
|
|
title: Node.js
|
|
homepage: https://nodejs.org
|
|
tagline: |
|
|
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
|
|
description: |
|
|
Node is great for simple, snappy HTTP(S) servers, and for stitching APIs together with minimal fuss or muss.
|
|
---
|
|
|
|
Hello World
|
|
|
|
```bash
|
|
node -e 'console.log("Hello, World!")'
|
|
> Hello, World!
|
|
```
|
|
|
|
A Simple Web Server
|
|
|
|
`server.js`:
|
|
|
|
```bash
|
|
var http = require('http');
|
|
var app = function (req, res) {
|
|
res.end('Hello, World!');
|
|
};
|
|
http.createServer(app).listen(8080, function () {
|
|
console.info('Listening on', this.address());
|
|
});
|
|
```
|
|
|
|
```bash
|
|
node server.js
|
|
```
|
|
|
|
An Express App
|
|
|
|
```bash
|
|
mkdir my-server
|
|
pushd my-server
|
|
npm init
|
|
npm install --save express
|
|
```
|
|
|
|
`app.js`:
|
|
|
|
```js
|
|
'use strict';
|
|
|
|
var express = require('express');
|
|
var app = express();
|
|
|
|
app.use('/', function (req, res, next) {
|
|
res.end("Hello, World!");
|
|
});
|
|
|
|
module.exports = app;</code></pre>
|
|
```
|
|
|
|
`server.js`:
|
|
|
|
```js
|
|
'use strict';
|
|
|
|
var http = require('http');
|
|
var app = require('./app.js');
|
|
|
|
http.createServer(app).listen(8080, function () {
|
|
console.info('Listening on', this.address());
|
|
});
|
|
```
|
|
|
|
```bash
|
|
npm start
|
|
```
|