steffen-wirth
10/15/2019 - 8:02 AM

host a node.js app

artikle on medium

1.Install nvm

wget -qO- https://cdn.rawgit.com/creationix/nvm/master/install.sh | bash
nvm install stable

node -v

npm -v

2.upload your application in web root folder

#create .htaccess and replace xxxxx with port of your app

RewriteEngine On
RewriteRule ^$ http://127.0.0.1:XXXXX/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:XXXXX/$1 [P,L]

3.run app.js forever

node app.js &

or

npm install -g forever
#start the server
forever start app.js

4.Problems

nvm: command not found

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"