How to host static site using pm2
pm2 is a process manager for node.js applications. You can use pm2 to host static websites.
To host a static website, create a folder, put your files inside.
1 |
mkdir /home/website |
Let’s create a static file, say index.html
1 |
echo "Welcome" > /home/website/index.html |
Now you can make the site live using the following pm2 command
1 |
pm2 serve /home/website 8082 |
Now the static site will be available at
1 |
http://localhost:8082 |
If you have a Single Page Application (SPA) like Angular, React, you can use the option –spa with pm2 command so all non-existent pages get routed to index.html internally.
1 |
pm2 serve --spa |