Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: Node.js Date: Thu, 14 Oct 2021 15:34:41 +0200 Lines: 54 Message-ID: References: <5f57e300-fd03-466c-96af-75fd67f72420n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net T4LemMAmAO2ZlthTiLJJJQMT7M01nxp1A0Q0tTrpoQdHiU7YCm Cancel-Lock: sha1:xgPvus95eQgKoke1fVSSycqnus8= In-Reply-To: Xref: csiph.com comp.lang.javascript:40474 Jonas Thörnvall: [...] > I am not sure what braindead monkey wrote that intro but.... > > "Now, run your web server using node app.js. Visit > http://localhost:3000 and you will see a message saying "Hello > World". Refer to the Introduction to Node.js for a more comprehensive > guide to getting started with Node.js." Why do you say "braindead monkey"? This is instruction is quite clear: 1) Run the command "node app.js" in your console 2) Open your browser and visit http://localhost:3000 > But i think he left out a couple of steps, like it should be run from > commandline, i got it running now. Of course! What else should "run your webserver using [node app.js]" mean? > Is it something similar to PHP, must the whole code base "vanilla > javascript" be generated dynamically thru the server? Or can i from > the clientside script invole functionality from server? Yes, Node.js runs completely on the server and *not* in the browser. Furthermore Node.js applications are designed to run continously while in PHP a script will only run once for the request then exit again (yes, PHP-FPM will continue running and waiting for the next request from the webserver but each PHP script will just be executed again for each incoming HTTP request). For example: The script app.js from will run as long as you don't stop the "node" process. The following function will handle all incoming requests from a browser: const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World'); }); "req" is the request object which contains everything sent by the browser and "res" is the response object which will generate the response sent back to the browser. -- Arno Welzel https://arnowelzel.de