Deploy the Node. js application in Ubuntu and use tunode. js
Install the Node. js Environment
sudo apt-get install nodejssudo apt-get install npm
For node_module dependent on different environments, use the following command to regenerate
rm -rf node_modulesnpm cache cleannpm install
If you do not want to use Node. js that comes with the system, you can use NVM
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | shsource ~/.profile
Run the following command to list and install the Node version:
nvm ls-remotenvm install 0.11.13nvm use 0.11.13node -v
If you have multiple Node. js versions, you can select
nvm lsnvm alias default 0.11.13nvm use default
Run the Node. js Program
node ./bin/www
How to deploy nodejs applications
For example, the main file in the main directory of your program is app. js.
You only need to enter the following in the command line:
Node app
You can start the program
How to deploy nodejs on heroku
Heroku is a cloud Application Deployment platform. You can deploy simple applications (including java, ruby, and node. js applications) on it ).
Here is just a test, so with the Express framework, you can deploy your own applications according to heroku's reference.
Register
First, you must register a heroku account. This is very simple, just a mailbox.
Download heroku's own command line tool Toolbelt
Here I am on the mac platform. With homebrew, you can directly install it with one click (brew install heroku). You can download the corresponding installation package from the official website on your own platform.
Log on to your computer
Open the command line, enter heroku login, and enter the account and password as prompted.
Start Application Deployment
This section describes how to deploy node. js applications. You can perform other operations on other applications by following the steps on the official website.
Deploy the node. js Application
Write Applications
Here I directly use express to generate an application
Modify the package. json File
Example:
{
"Name": "MyMobile ",
"Version": "0.0.1 ",
"Private": true,
"Scripts ":{
"Start": "node app. js ",
"Postinstall": "./node_modules/bower/bin/bower install"
},
"Dependencies ":{
"Express ":"~ 3.4.5 ",
"Jade ":"*",
"Bower ":"*"
},
"Engines ":{
"Node": "0.10.x ",
"Npm": "1.3.x"
}
}
Add a Procfile File
Note that the Procfile file should be placed in the root directory named Procfile. Simply add one web: node web. js.
Use git to create a repository
Deploy to heroku
Heroku create
Git push heroku master
Run the application
Command Line input heroku ps: scale web = 1
You can check whether the deployment is successful. Enter heroku ps in the command line. If the output is normal, the deployment is successful.
View
Enter heroku open in the command line to open the browser, which automatically displays the application you are running in the browser.
Add your own domain name
In the DNS resolution area, use CNAME to map your own domain name to the domain name assigned to you by heroku.
Here I also use bower, so a bower command is used in package. json. In this way, heroku will automatically download the corresponding library according to the dependencies in your bower. json before running. In this way, you do not need to add these libraries to the repository to reduce the project volume.
Link to the original article:... the remaining full text>