Quick Index
References



Setup


Using this example

Run:

npm install npm -g
mkdir ~/.npm-packages
npm config set prefix ~/.npm-packages


Run:

mkdir "${HOME}/.npm-packages"
echo NPM_PACKAGES="${HOME}/.npm-packages" >> ${HOME}/.bashrc
echo prefix=${HOME}/.npm-packages >> ${HOME}/.npmrc
echo NODE_PATH=\"\$NPM_PACKAGES/lib/node_modules:\$NODE_PATH\" >> ${HOME}/.bashrc
echo PATH=\"\$NPM_PACKAGES/bin:\$PATH\" >> ${HOME}/.bashrc
echo source "~/.bashrc" >> ${HOME}/.bash_profile
source ~/.bashrc


Deploy



Install PM2


In development, we typically run in the foreground, e.g., "node hello-world.js".

But in production we want to run processes in background.

PM2 runs a process in the background.

Install PM2
npm install -g pm2


Start/Stop App Using PM2


Start App
pm2 start -n "test pm2" hello-world.js
Stop App
pm2 stop java-code-lab
pm2 stop 'test 2 -- pm2'


List Running Processes


pm2 list


Open App in Browser


http://objectcoding.com:3000/
http://objectcoding.com:3000/split.html?exampleIds=11111|1111
http://objectcoding.com:3000/split.html?exampleIds=11141|1141&sourceCode=wow


Example Steps


Example: (java-code-lab) -- project dir is "v2"

(on dev box)
Delete dir "node_modules"
Zip up to v2.zip
Copy to prod server

(on prod box)
unzip v2.zip
Go to "v2" dir
Run: npm install
//Stop current service
pm2 stop java-code-lab
//Start service
go to "v2" directory
pm2 start -n "java-code-editor" app.js
//List services
pm2 list


Logs



pm2 logs

pm2 flush