Node.js Get Started

Download Node.js

The official Node.js website has installation instructions for Node.js:

Getting Started

Once you have downloaded and installed Node.js on your computer, let’s try to display “Hello World” in a web browser.

Create a Node.js file named “myfirst.js”, and add the following code:

var http = require('http');

http.createServer(function (req, res) {
  res.end('Hello World!');

Save the file on your computer: C:\Users\Your Name\myfirst.js

The code tells the computer to write “Hello World!” if anyone (e.g. a web browser) tries to access your computer on port 8080.

For now, you do not have to understand the code. It will be explained later.

Command Line Interface

Node.js files must be initiated in the “Command Line Interface” program of your computer.



C:\Users\Your Name>_

Initiate the Node.js File



Initiate “myfirst.js”:

C:\Users\Your Name>node myfirst.js

Now, your computer works as a server!



Trả lời
