Simple steps to build the Node. js development environment in Linux, linuxnode. js

Source: Internet
Author: User
Tags install node

Simple steps to build the Node. js development environment in Linux, linuxnode. js

1. Install node. js in Linux


sudo apt-get install nodejs npm


yum install nodejs npm

For more detailed installation see:
Npm is a package manager similar to Pear in PHP

2. Start using node. js

Use the text editor to create hello. js and write the following content

console.log('hello world');

Open command line Input

$ node hello.js

You will see the output

 $ hello world

Console. log is the most common output command.

3. Create an HTTP server

Understanding node. js Architecture
The PHP architecture model is:
Browser -- HTTP server (apache, nginx) -- PHP interpreter

In node. js applications, node. js adopts the following methods:
Browser -- node. js Architecture

Create an HTTP server: Create an app. js file with the following content:

var http = require('http');http.createServer(function(req, res){  res.writeHead(200,{'Content-Type': 'text/html'});  res.write('</pre>


$ node app.js

Open the browser and open http: // 3000 to view the result.

This program calls the http module provided by node. js, replies the same content to all Http requests, and listens to port 3000. After the script is run, it does not exit immediately. You must press ctro + c to stop it. This is because the listen function creates an event listener.

4. debug the script

After the node. js script is modified, you must stop the original program and run it again to see the changes.
Use the Package Manager to install the supervisor tool.

$ npm install -g supervisor

Later pass

$ supervisor app.js

To run the node. js program. It will detect program code changes and automatically restart the program.
Note: You must obtain the root permission during installation.

Articles you may be interested in:
  • Use the Package Manager in linux to install node. js
  • Node. js getting started Tutorial: install and configure Node. js on windows and Linux
  • Enable ECMAScript 6 in NodeJS (windos and Linux)
  • Use forever in Linux to implement self-starting Node. js Projects
  • Start nodemanager on linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.