Editors Choice

3/recent/post-list

Ad Code

Responsive Advertisement

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's.

setting that works for me to setup running apps (series) 2



so it turns out, setup the system to always run your site is not that simple 

first lets dive in 

go to your application 

cd /home/ubuntu/code-canvas-tool
npm run build

and them install the serve 
npm install -g serve
serve -s dist

use this

sudo vim /etc/systemd/system/myapp.service

[Unit]
Description=Node.js App
After=network.target

[Service]
WorkingDirectory=/home/ubuntu/code-canvas-tool
ExecStart=/usr/bin/serve -s dist -l 8080
Restart=always
User=ubuntu
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

reload the application 
sudo systemctl daemon-reload
sudo systemctl restart myapp
sudo systemctl status myapp

here Run Node.js App with systemd on EC2

🚀 Setting up systemd to Always Run Your Site on EC2

It turns out, setting up the system to always run your site is not that simple. Let’s walk through it step by step.

1. Go to Your Application

cd /home/ubuntu/code-canvas-tool
npm run build

2. Install serve

npm install -g serve
serve -s dist

3. Create a systemd Service

Open the service file:

sudo vim /etc/systemd/system/myapp.service

Paste the following content:

[Unit]
Description=Node.js App
After=network.target

[Service]
WorkingDirectory=/home/ubuntu/code-canvas-tool
ExecStart=/usr/local/bin/serve -s dist -l 8080
Restart=always
User=ubuntu
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

4. Reload and Restart the Service

sudo systemctl daemon-reload
sudo systemctl restart myapp
sudo systemctl status myapp

✅ Now your app will always run in the background, even after reboot.

Post a Comment

0 Comments