{
  "source": "doc/api/synopsis.md",
  "introduced_in": "v0.10.0",
  "miscs": [
    {
      "textRaw": "Usage",
      "name": "Usage",
      "introduced_in": "v0.10.0",
      "type": "misc",
      "desc": "<p><code>node [options] [V8 options] [script.js | -e &quot;script&quot; | - ] [arguments]</code></p>\n<p>Please see the <a href=\"cli.html#cli_command_line_options\">Command Line Options</a> document for information about\ndifferent options and ways to run scripts with Node.js.</p>\n<h2>Example</h2>\n<p>An example of a <a href=\"http.html\">web server</a> written with Node.js which responds with\n<code>&#39;Hello World!&#39;</code>:</p>\n<p>Commands displayed in this document are shown starting with <code>$</code> or <code>&gt;</code>\nto replicate how they would appear in a user&#39;s terminal.\nDo not include the <code>$</code> and <code>&gt;</code> character they are there to\nindicate the start of each command.</p>\n<p>There are many tutorials and examples that follow this\nconvention: <code>$</code> or <code>&gt;</code> for commands run as a regular user, and <code>#</code>\nfor commands that should be executed as an administrator.</p>\n<p>Lines that don’t start with <code>$</code> or <code>&gt;</code> character are typically showing\nthe output of the previous command.</p>\n<p>Firstly, make sure to have downloaded and installed Node.js.\nSee <a href=\"https://nodejs.org/en/download/package-manager/\">this guide</a> for further install information.</p>\n<p>Now, create an empty project folder called <code>projects</code>, navigate into it:\nProject folder can be named base on user&#39;s current project title but\nthis example will use <code>projects</code> as the project folder.</p>\n<p>Linux and Mac:</p>\n<pre><code class=\"lang-console\">$ mkdir ~/projects\n$ cd ~/projects\n</code></pre>\n<p>Windows CMD:</p>\n<pre><code class=\"lang-console\">&gt; mkdir %USERPROFILE%\\projects\n&gt; cd %USERPROFILE%\\projects\n</code></pre>\n<p>Windows PowerShell:</p>\n<pre><code class=\"lang-console\">&gt; mkdir $env:USERPROFILE\\projects\n&gt; cd $env:USERPROFILE\\projects\n</code></pre>\n<p>Next, create a new source file in the <code>projects</code>\n folder and call it <code>hello-world.js</code>.</p>\n<p>In Node.js it is considered good style to use\nhyphens (<code>-</code>) or underscores (<code>_</code>) to separate\n multiple words in filenames.</p>\n<p>Open <code>hello-world.js</code> in any preferred text editor and\npaste in the following content.</p>\n<pre><code class=\"lang-js\">const http = require(&#39;http&#39;);\n\nconst hostname = &#39;127.0.0.1&#39;;\nconst port = 3000;\n\nconst server = http.createServer((req, res) =&gt; {\n  res.statusCode = 200;\n  res.setHeader(&#39;Content-Type&#39;, &#39;text/plain&#39;);\n  res.end(&#39;Hello World!\\n&#39;);\n});\n\nserver.listen(port, hostname, () =&gt; {\n  console.log(`Server running at http://${hostname}:${port}/`);\n});\n</code></pre>\n<p>Save the file, go back to the terminal window enter the following command:</p>\n<pre><code class=\"lang-console\">$ node hello-world.js\n</code></pre>\n<p>An output like this should appear in the terminal to indicate Node.js\nserver is running:</p>\n<pre><code class=\"lang-console\">Server running at http://127.0.0.1:3000/\n</code></pre>\n<p>Now, open any preferred web browser and visit <code>http://127.0.0.1:3000</code>.</p>\n<p>If the browser displays the string <code>Hello, world!</code>, that indicates\nthe server is working.</p>\n<p>Many of the examples in the documentation can be run similarly.</p>\n"
    }
  ]
}
