{ "source": "doc/api/synopsis.md", "miscs": [ { "textRaw": "Usage", "name": "Usage", "type": "misc", "desc": "

node [options] [v8 options] [script.js | -e "script"] [arguments]

\n

Please see the Command Line Options document for information about\ndifferent options and ways to run scripts with Node.js.

\n

Example

\n

An example of a web server written with Node.js which responds with\n'Hello World':

\n
const http = require('http');\n\nconst hostname = '127.0.0.1';\nconst port = 3000;\n\nconst server = http.createServer((req, res) => {\n  res.statusCode = 200;\n  res.setHeader('Content-Type', 'text/plain');\n  res.end('Hello World\\n');\n});\n\nserver.listen(port, hostname, () => {\n  console.log(`Server running at http://${hostname}:${port}/`);\n});\n
\n

To run the server, put the code into a file called example.js and execute\nit with Node.js:

\n
$ node example.js\nServer running at http://127.0.0.1:3000/\n
\n

All of the examples in the documentation can be run similarly.

\n" } ] }