I have node.js app that I'm trying to deploy in production mode using systemd to restart it should the server crash/reboot. The app works fine when I start it using 'node app.js' (i.e. all my public files are found). However, when I kill the process and systemd restarts it, Express can no longer locate my css/js files. I'm using connect-assets to concatenate my css/js files.
I think think the problem is my node path, but I'm not entirely sure. This is the error that I see in my browser when systemd restarts the app:
500 Error ...
> 11| != css('styles')
12| != js('application')
No file found for route css/styles.css
When I examine the process that I manually started using the 'node app.js' command I see:
ghost 30222 6.8 17.8 140348 90848 pts/0 Sl+ 18:01 0:08 node app.js
And when systemd restarts the app I see the following:
ghost 30332 5.5 9.1 94036 46516 ? Ssl 18:05 0:01 /usr/local/bin/node /home/ghost/myapp/app.js
Here is my service file:
[Service]
ExecStart=/usr/local/bin/node /home/ghost/myapp/app.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=node-sample
User=ghost
Group=ghost
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
You need to set
WorkingDirectory=to the top-level directory of your Node app, wherever that is.For example:
or for global-installed apps,