SoftTimur
SoftTimur

Reputation: 5520

Grant the server the permission of creating a folder

I have a Ubuntu Server on DigitalOcean, which hosts some websites. I just built a mean.js stack app on my mac, and I plan to deploy it to production, thus to this existing server.

I followed this link to install node.js and mongodb, etc. Then, rather than cloning the sample app of mean.js, I cloned my own app from the github:

sudo git clone https://github.com/softtimur/myapp.git /opt/myapp
cd /opt/myapp
sudo mkdir public/tmp/
sudo npm install
npm start

Then, in a browser, I entered https://xxx.xx.xx.xx:3000/#/new. On the server side, I got an error:

router.post /mkdir
{ Error: EACCES: permission denied, mkdir 'public/tmp/sAlTI6NDo5NQcO-lAAAA/'
    at Error (native)
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: 'public/tmp/sAlTI6NDo5NQcO-lAAAA/' }

This is because in the backend of my app, it tries to create a folder in public/tmp/ by fs.mkdir(...) where fs = require('fs').

So does anyone know to how to give the server this permission?

PS: I also tried to run

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config

but it did not help.

Upvotes: 1

Views: 3108

Answers (1)

robertklep
robertklep

Reputation: 203419

The issue is that you created public/tmp/ as root:

sudo mkdir public/tmp/

But you're running the app as $USER, which will most likely not be allowed to write to that directory.

To fix:

sudo chown -R $USER:$GROUP public/tmp/

Upvotes: 2

Related Questions