mirror of https://github.com/lukechilds/node.git
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.
30 lines
631 B
30 lines
631 B
13 years ago
|
# Synopsis
|
||
|
|
||
|
<!--type=misc-->
|
||
14 years ago
|
|
||
9 years ago
|
An example of a [web server][] written with Node.js which responds with
|
||
9 years ago
|
`'Hello World'`:
|
||
14 years ago
|
|
||
9 years ago
|
```js
|
||
|
const http = require('http');
|
||
14 years ago
|
|
||
9 years ago
|
http.createServer( (request, response) => {
|
||
|
response.writeHead(200, {'Content-Type': 'text/plain'});
|
||
|
response.end('Hello World\n');
|
||
|
}).listen(8124);
|
||
14 years ago
|
|
||
9 years ago
|
console.log('Server running at http://127.0.0.1:8124/');
|
||
|
```
|
||
14 years ago
|
|
||
|
To run the server, put the code into a file called `example.js` and execute
|
||
10 years ago
|
it with the node program
|
||
14 years ago
|
|
||
9 years ago
|
```
|
||
9 years ago
|
$ node example.js
|
||
9 years ago
|
Server running at http://127.0.0.1:8124/
|
||
|
```
|
||
14 years ago
|
|
||
|
All of the examples in the documentation can be run similarly.
|
||
9 years ago
|
|
||
|
[web server]: http.html
|