Writing a Simple Node.js Script
Simple Node.js
Let's write a simple Node.js script that outputs "Hello, World!" to the console. To do this, we'll use the built-in "console" module.
In this script, we first import the http
module, which is built into Node.js. Then, we create a constant for the hostname and port number that our server will listen on.
Next, we use the createServer
method of the http
module to create an HTTP server that outputs "Hello, World!" when a request is made to the server.
Finally, we start the server using the listen
method and specify the hostname and port number that the server should listen on.
Last updated