Get Free DigitalOcean $100 Credit 👨💻 Grab it now. Deploy faster & scale easier with an application server that saves your team time & money.
Apache Server Configuration
sudo apt update && sudo apt install apache2
Configure Firewall
sudo ufw allow OpenSSH
sudo ufw allow in "Apache Full"
sudo ufw enable
sudo ufw status
ufw app list
ufw allow 7000
Open any port number example: 7000 open outsite localhost
for more info about ufw
firewall
cd ..
Goto previous directory
cd /
Goto root directory
pwd
Print work directory
ls
Show current directory info
md
or mkdir
make folder/directory
apt-get update
update new essential
sudo
used this if you not root user
ssh [email protected]
example: ssh [email protected]
open server using CMD/powershel using
password:
then enter your password
install the latest LTS release of Node.js
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - sudo apt install -y nodejs
Another way install NodeJS
check the
node.js
version andnpm
version using the following commands
node -v
npm -v
Some packages requires compiling from source so you need to install the
build-essential
package
sudo apt install build-essential
Now you can create a demo Node.js app
cd /
Goto root
sudo nano server.js
or vim server.js
Insert the following code into the file
const http = require('http');
const hostname = 'localhost';
const port = 7000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Welcome to Node.js!\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Paste and Save the file and exit.
vim: esc :wq enter
or nano: ctrl+x y enter
sudo npm install [email protected] -g
Now you can start your app using the process manager
pm2 start server.js
Server continue on without downtime
pm2 startup systemd
Now your Node.js application is running in the background
Remove default Apache configuration.
sudo a2dissite 000-default
Create a new virtual host configuration for Node.js.
sudo nano /etc/apache2/sites-available/domain.conf
Add the below configurations to the file.
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://127.0.0.1:7000/
ProxyPassReverse / http://127.0.0.1:7000/
</VirtualHost>
Hit
CTRL + X
followed byY
andEnter
to save and close the file.
Enable the newly created configuration.
sudo a2ensite domain.conf
Now you can restart Apache.
sudo service apache2 restart
ufw allow 7000
open or allow access for outsite
ufw reload
reload ufw rule
Now you can restart Apache.
sudo service apache2 restart
pm2 start server.js
Check your server active or not
curl http://localhost:7000
To list all running applications:
pm2 list
Managing apps is straightforward:
pm2 stop <app_name|namespace|id|'all'|json_conf>
pm2 restart <app_name|namespace|id|'all'|json_conf>
pm2 delete <app_name|namespace|id|'all'|json_conf>
To have more details on a specific application:
pm2 describe <id|app_name>
To monitor logs, custom metrics, application information:
pm2 monit
Starting a Node.js application in cluster mode that will leverage all CPUs available:
pm2 start api.js -i <processes>
Hot Reload allows to update an application without any downtime:
pm2 reload all
pm2 save
# Install latest PM2 version
npm install [email protected] -g
# Save process list, exit old PM2 & restore all processes
pm2 update
pm2 examples
sudo apt update
sudo apt install mongodb-org
or sudo apt install mongodb
Open mongoDB type: mongo
sudo apt-get remove nodejs
sudo apt-get purge nodejs