Server IP : 85.214.239.14 / Your IP : 18.227.46.54 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/self/root/usr/share/doc/nodejs/api/ |
Upload File : |
{ "type": "module", "source": "doc/api/synopsis.md", "modules": [ { "textRaw": "Usage and example", "name": "usage_and_example", "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 \"script\" | - ] [arguments]</code></p>\n<p>Please see the <a href=\"cli.html#options\">Command-line options</a> document for more information.</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>'Hello, World!'</code>:</p>\n<p>Commands in this document start with <code>$</code> or <code>></code> to replicate how they would\nappear in a user's terminal. Do not include the <code>$</code> and <code>></code> characters. They are\nthere to show the start of each command.</p>\n<p>Lines that don't start with <code>$</code> or <code>></code> character show the output of the previous\ncommand.</p>\n<p>First, make sure to have downloaded and installed Node.js. See\n<a href=\"https://nodejs.org/en/download/package-manager/\">Installing Node.js via package manager</a> for further install information.</p>\n<p>Now, create an empty project folder called <code>projects</code>, then navigate into it.</p>\n<p>Linux and Mac:</p>\n<pre><code class=\"language-bash\">mkdir ~/projects\ncd ~/projects\n</code></pre>\n<p>Windows CMD:</p>\n<pre><code class=\"language-powershell\">mkdir %USERPROFILE%\\projects\ncd %USERPROFILE%\\projects\n</code></pre>\n<p>Windows PowerShell:</p>\n<pre><code class=\"language-powershell\">mkdir $env:USERPROFILE\\projects\ncd $env:USERPROFILE\\projects\n</code></pre>\n<p>Next, create a new source file in the <code>projects</code>\nfolder and call it <code>hello-world.js</code>.</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=\"language-js\">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});\n</code></pre>\n<p>Save the file. Then, in the terminal window, to run the <code>hello-world.js</code> file,\nenter:</p>\n<pre><code class=\"language-bash\">node hello-world.js\n</code></pre>\n<p>Output like this should appear in the terminal:</p>\n<pre><code class=\"language-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>" } ], "type": "module", "displayName": "Usage and example" } ] }