mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
Original commit: https://github.com/nodejs/node/commit/0800c0aa7275bf389b157e1568fa61b59285ad86 doc: git mv to .md * doc: rename .markdown references in content * doc: rename to .md in tools * doc: rename to .md in CONTRIBUTING.md PR-URL: #4747 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: techjeffharris Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
44 lines
982 B
Markdown
44 lines
982 B
Markdown
# Usage
|
|
|
|
<!--type=misc-->
|
|
|
|
`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.
|
|
|
|
## Example
|
|
|
|
An example of a [web server][] written with Node.js which responds with
|
|
`'Hello World'`:
|
|
|
|
```js
|
|
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.
|
|
|
|
[Command Line Options]: cli.html#cli_command_line_options
|
|
[web server]: http.html
|