mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 23:16:30 +01:00
a58b48bc3b
* Fix markdown code sample in releases.md, it was <a id="x.y.x></a>" * Fix some markdown errors, e.g. in changelogs * Fix broken defs links, e.g. in domain-postmortem.md * Fix other broken refs, by addaleax * Add links to some defs that were present but not linked to * Remove dead defs * Move defs to the bottom (one file affected) * Add language indicators to all code blocks, using `txt` when no specific language could be chosen * Some minor formatting changes (spaces, ident, headings) PR-URL: https://github.com/nodejs/node/pull/7637 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Roman Reiss <me@silverwind.io>
988 B
988 B
Usage
node [options] [v8 options] [script.js | -e "script"] [arguments]
Please see the Command Line Options document for information about different options and ways to run scripts with Node.js.
Example
An example of a web server written with Node.js which responds with
'Hello World'
:
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
To run the server, put the code into a file called example.js
and execute
it with Node.js:
$ node example.js
Server running at http://127.0.0.1:3000/
All of the examples in the documentation can be run similarly.