Install Node.js on Centos

Introduction

Node.js is an open source, cross-platform avaScript runtime environment that can run JavaScript on the server side. Node.js is owned and maintained by the Node.js Foundation and has a cooperative relationship with the Linux Foundation. Node.js uses the V8 running code developed by Google, and uses event-driven, non-blocking and asynchronous input and output models to improve performance and optimize the transfer volume and scale of the application. These techniques are often used in data-intensive real-time applications. Most of the basic modules of Node.js are written in JavaScript. Before Node.js appeared, JavaScript was usually used as a client-side programming language, and programs written in JavaScript were often run on the user's browser. The emergence of Node.js enables JavaScript to also be used for server-side programming.

Therefore, learning to try Node.js is very useful. This article outlines the steps required to run "Hello world" in Centos running node.js + express.

**Settings **CVM

First of all, we need a CVM (the smallest is enough), if it’s just an experiment, I recommend you to use Tencent Cloud free Developer Lab for use, and a SSH clients (such as Putty on Windows, SSH on Linux systems and Mac OSX, which are usually built-in). When we receive the initial root password, we can use ssh to apply it to the instance. Use SSH to enter CVM and change the root password. It is best to update the software repository to the latest version:

yum -y update

This will update the software installed on our CVM to the latest version. Yum may take a few minutes. When it is finished, we need to prepare the software for installation. We will build Node.js from the latest source code. At the time of writing this article, the latest version is v0.10.4. For this, we need "development tools". It is a set of tools for compiling software from source code.

yum -y groupinstall "Development Tools"

This command will extract the "Development Tools" group with the application required to compile node.js.

In addition, we will install screen, a software that can make your SSH background work. It is very convenient, especially when developing and compiling.

yum -y install screen

Install Node.js

Now we are ready to install Node.js from source. First, we will move to the /usr/src directory, which is usually used to store software sources.

cd /usr/src

Now, we select the latest compressed source archive from the Node.js website http://nodejs.org/download.

wget http://nodejs.org/dist/v0.10.4/node-v0.10.4.tar.gz

If there is a new version, we recommend that you replace the version in the url. Next, we unzip the source file and enter the directory.

tar zxf node-v0.10.4.tar.gz
cd node-v0.10.4

Now extract the source code of Node.js, we are in the source directory. We can now prepare our compiler commands by executing the configure script:

. /configure

This will read the properties of our system to prepare the contents of the compiler, for example, it will read your system architecture (32/64 bit, CPU, etc.). With it, we are now ready to actually compile the source code. Just enter:

make

This is probably the most time-consuming task: on CVM, it takes about 6 minutes and 34 seconds to complete. When we are finished, we can use the installation:

make install

The latest command puts the compiled binary file in the system path, so all users can use it without further settings. By default, node binaries should be installed in /usr/local/bin/node.

Install Express.js

We have now installed and completed Node.js, we can start development, deploy the completed application, or we can install the Express.js web framework. First, we will use the node module manager (npm) to quickly install plugins and management programs. This is a very useful module that can keep our application started, monitor file changes (for example, when developing an application) and when needed Restart CVM.

npm -g install express express-generator supervisor

npm -g install will install the express and supervisor modules from the npm software repository and make them available to the entire system. The -g flag in this command means "global".

Add non-privileged user

For security reasons, you should now create a regular system user and run the node under an unprivileged account.

To do this, please add users first. You can replace "exampleuser" with any name you like.

useradd exampleuser

Now we have a new system user. Add a suitable password for the new user:

passwd exampleuser

**Log out, and then log back in as the new user. **

This will change our login shell from root (system user) to exampleuser (non-privileged user, which can destroy the system with less damage).

Create a quick application

Express is a powerful framework. To create our first application, all we have to do is enter:

express hello

This command will create a "hello" directory and make some basic settings for the new application. Now we should go into this directory and install express dependencies:

cd hello && npm install

The npm install command will read all module dependencies from the generated package.json file and install it from the npm software repository. We should start a new screen session so that our node can run:

screen

Finally, we can start our application.

supervisor ./bin/www

Now, we can access our first express application through your CVM IP. For example, http://123.456.78.90:3000.

Have you learnt that? For more Nodejs basic tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn.


Reference: "How To Install And Run A Node.js App On Centos 6.4 64bit"

Recommended Posts

Nodejs install on centos7
Install Node.js on Centos
CentOS install nodejs 8
Install Docker on Centos7
install LNMP on centos7.4
Install Java on Centos 7
Install nodejs10 on Ubuntu16
CentOS6.8 install node.js npm
Maven install on centos7
Install MongoDB on CentOS 7
Install Surelog on CentOS8
Openjdk install on centos7
Install Jenkins on centos7
install RabbitMQ on centos
Install RabbitMQ on CentOS 7
install Docker on centos6.5
install oracle on centos
Install Elasticsearch 6 on centos7
Install RabbitMQ on CentOS7
Install ElasticSearch 7.x on CentOS 7
Install docker transfer on Centos7
How to install Node.js and npm on CentOS 8
Install docker on Centos system
install EPEL repo on centos
1.5 Install Centos7
Install Zabbix 3.4 based on CentOS 7
install virtualbox on centos server
Install Nginx server on CentOS 7
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
Install JDK8 in rpm on CentOS7
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
How to install Node.js on Ubuntu 16.04
How to install TeamViewer on CentOS 8
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Jenkins on CentOS 8
How to install Go on CentOS 8
How to install GCC on CentOS 8
How to install Yarn on CentOS 8
How to install Nginx on CentOS 8
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
Install MySQL on Linux CentOS7 (Windows)
How to install Vagrant on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8
​Install Oracle database on CentOS Linux
How to install Python on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
How to install htop on CentOS 8
How to install TeamViewer on CentOS 8