{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"synopsis","path":"/synopsis","type":"misc","module":null,"title":"Usage and example","introducedIn":"v0.10.0","sourceLink":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"usage","name":"Usage","title":"Usage","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"`node [options] [V8 options] [script.js | -e \"script\" | - ] [arguments]`\n\nPlease see the [Command-line options](cli.html#options) document for more information.","summary":"`node [options] [V8 options] [script.js | -e \"script\" | - ] [arguments]`","examples":[],"children":[]},{"kind":"section","id":"example","name":"Example","title":"Example","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"An example of a [web server](http.html) written with Node.js which responds with\n`'Hello, World!'`:\n\nFirst, make sure to have downloaded and installed Node.js. See\n[Installing Node.js](https://nodejs.org/en/download) for further install information.\n\nNow, create an empty project folder called `projects`, then navigate into it.\n\nLinux and Mac:\n\n```bash\nmkdir ~/projects\ncd ~/projects\n```\n\nWindows CMD:\n\n```powershell\nmkdir %USERPROFILE%\\projects\ncd %USERPROFILE%\\projects\n```\n\nWindows PowerShell:\n\n```powershell\nmkdir $env:USERPROFILE\\projects\ncd $env:USERPROFILE\\projects\n```\n\nNext, create a new source file in the `projects`\nfolder and call it `hello-world.js`.\n\nOpen `hello-world.js` in any preferred text editor and\npaste in the following content:\n\n```js\nconst http = require('node: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\nSave the file. Then, in the terminal window, to run the `hello-world.js` file,\nenter:\n\n```bash\nnode hello-world.js\n```\n\nOutput like this should appear in the terminal:\n\n```console\nServer running at http://127.0.0.1:3000/\n```\n\nNow, open any preferred web browser and visit `http://127.0.0.1:3000`.\n\nIf the browser displays the string `Hello, World!`, that indicates\nthe server is working.","summary":"An example of a web server written with Node.js which responds with `'Hello, World!'`:","examples":[{"language":"bash","displayName":null,"code":"mkdir ~/projects\ncd ~/projects"},{"language":"powershell","displayName":null,"code":"mkdir %USERPROFILE%\\projects\ncd %USERPROFILE%\\projects"},{"language":"powershell","displayName":null,"code":"mkdir $env:USERPROFILE\\projects\ncd $env:USERPROFILE\\projects"},{"language":"js","displayName":null,"code":"const http = require('node: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});"},{"language":"bash","displayName":null,"code":"node hello-world.js"},{"language":"console","displayName":null,"code":"Server running at http://127.0.0.1:3000/"}],"children":[]}]}