1
votes

I have a VPS(ubuntu 14.04) and a nodejs app with multer for handler file upload and it works find when I start the server via node ex."node my-server.js"

but not if I start via upstart ex."sudo start node-app" node-app is a ubuntu upstart conf file here is the code

multer I use with express here is the code. my-server.js

app.use(multer({
  dest: './public/images/',
  rename: function(fieldname, filename) {
    return filename;
  }
}));

my upstart file: /etc/init/node-app.conf

description "node.js server"
author      "Name"

start on (local-filesystems and net-device-up IFACE=wlan0)

stop on shutdown

# Automatically Respawn:
respawn
respawn limit 99 5

script
    export HOME="/home/username/www/site-server/"
    exec node $HOME/bin/www 13002 >> /var/log/node.log 2>&1
end script

on my node.log I have this.

{ [Error: Command failed: identify.im6: unable to open image `/home/username/www/my-node-app/public/images/hqdefault.jpg': No such file or directory @ error/blob.c/OpenBlob/2638.
] timedOut: false, killed: false, code: 1, signal: null }

any idea why is not working via upstart?

2
Are any errors being logged? My guess would be that it's a working directory issue, but that's speculation at this point.robertklep
@robertklep thanks for your response I have update the issue. That is what I get on my node.log file.diegoddox

2 Answers

0
votes

It needs to be able to write uploaded files to disk, so it probably doesn't have permission to write to the destination directory.

Ensure that upstart runs it from user account that has access to upload directory you've configured in multer.

0
votes

Well as @porneL has said the ubuntu user need permission to write on the disk so I have changed my upstart file.

from this.

export HOME="/home/username/www/site-server/"
exec node $HOME/bin/www 13002 >> /var/log/node.log 2>&1

to this

export HOME="/home/username/www/"
cd $HOME/site-server/
exec node bin/www >> /var/log/node.log 2>&1

Here is where I find the answer.