NODEJS application deployment in Linux servers

Source: Internet
Author: User
Tags openssl build install node

1. (optional) Add Users:

addgroup wmuiTo add a user group
useradd -d /home/wmui -s /bin/bash -m wmuiCreate Wmui User
passwd wmuiSet the password, if you forget the password, you can also use this command to reset the password
usermod -a -G wmui wmuiAdd user to Group
visudo Setting sudo permissions
Then it jumps to the following page

root ALL=(ALL:ALL) ALLAdd the followingwmui ALL=(ALL) NOPASSWD: ALL
ctrl+xSave exit
Next, open a new window to test whether the login was successful.

2. (optional) SSH no password login configuration

First you need to install git locally and build id_rsa.pub it, open the command line
Generate the public and private keys locally:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Generate the public and private keys on the server:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
In the Server window, enter:
echo "[your public key]" > ~/.ssh/authorized_keysCopy the local public key to the server's Authorized_keys file

Complete the above operation, the test is effective, restart the service: sudo service ssh restart Open a new window, enter the user name return, login success

3.NODEJS Environment Construction

Install common software
sudo apt-get install vim openssl build-essential libssl-dev wget curl git
NVM installation
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
Open a new window
nvm install node v8.1.3  这里也可以下载编译好的压缩包进行安装
nvm use node v8.1.3
nvm alias default v8.1.3Default version
Install common node Packages
npm i pm2 webpack vue-cli -g

4. Create and deploy Hello World

As root user in the root directory to create the WWW directory, the WWW directory created Mynodeapp folder, inside a file, App.js, the contents are as follows:

 const  http = require ( " http  "  ) http.createserver (function (req,res) {res.writehead ( 200 , { content-type   ' : 

(If you are using an application that is written in conjunction with the NODEJS framework such as Express, which contains Package.json), copy the project code directly to the WWW directory and enter the project directory, such as Mynodeapp, to execute the command

NPM install dependency. )

Go to www under Mynodeapp folder
Hello World test:
PM2 Start App.js
PM2 List View launched apps
PM2 Show Hello View more information
PM2 Logs View current information
PM2 Stop Hello stops hello
PM2 Delete Hello Remove hello

Indicates successful startup, enter Hello.86886.wang to see Hello World.

NODEJS application deployment in Linux servers

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.