Quickly learn how to install and run the Node. js environment and the node. js Environment

Source: Internet
Author: User
Tags node server

Quickly learn how to install and run the Node. js environment and the node. js Environment

Installer
NodeJS provides some installation programs that can be downloaded and installed at nodejs.org.

In Windows, select an installation file with the. msi suffix that matches the system version. In Mac OS X, select the installation file with the. pkg suffix.

Compile and install
There are no ready-made installation programs available in Linux. Although some release versions can be installed using apt-get or other methods, they may not be installed to the latest version. Therefore, NodeJS is usually installed in the following way in Linux.

1. Make sure that the g ++ version is later than 4.6 and the python version is later than 2.6.

2. download the latest NodeJS source code package with the extension tar.gz from nodejs.org and decompress it to a certain location.

3. Go to the decompressed directory and run the following command to compile and install the package.

$ ./configure$ make$ sudo make install

Run

Open the terminal and type node to enter the command interaction mode. You can enter a code statement and execute it immediately and display the result, for example:

$ node> console.log('Hello World!');Hello World!

If you want to run a large piece of code, you can write a JS file before running it. For example, the following is hello. js.

function hello() {  console.log('Hello World!');}hello();

After writing the code, enter node hello. js in the terminal to run it. The result is as follows:

$ node hello.jsHello World!

Permission problems
In Linux, the root permission is required to use NodeJS to listen to port 80 or port 443 to provide the HTTP (S) service. There are two ways to do this.

One way is to run NodeJS using the sudo command. For example, the server. js running through the following command has the permission to use port 80 and port 443. This method is generally recommended to ensure that only the root permission is provided for JS scripts that are needed.

$ sudo node server.js

Another method is to use the chmod + s command to make NodeJS always run with the root permission. The specific method is as follows. This method gives any JS script the root permission, which is not safe. Therefore, it is not recommended to use it in a secure system.

$ sudo chown root /usr/local/bin/node$ sudo chmod +s /usr/local/bin/node

Articles you may be interested in:
  • Install and configure the node. js + express development environment in win7
  • How to install Node. JS on Ubuntu
  • Install nodejs and framework express in windows
  • Install nodejs in ubuntu and how to upgrade it
  • Install Node. js and mongodb notes on CentOS
  • Use the Package Manager in linux to install node. js
  • Introduction, installation and configuration of Node. js Study Notes
  • Install and configure iisnode extension IIS running Node. js
  • How to install nodejs in Windows
  • Simple nodejs installation and environment configuration in windows

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: info-contact@alibabacloud.com 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.