nodejs fs eacces permission - node.js

I've just run into a strange problem with fs reading a file.
I have node application run from a deployment manager (strongloop strong-pm) as the following user "strong-pm".
No matter what permissions I give to the file I'm trying to open throug the node app, I get
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
worker:1 Error: EACCES, permission denied '/root/my_dir/file.txt'
at Object.fs.openSync (fs.js:432:18)
at Object.fs.readFileSync (fs.js:286:15)
I've tried everything:
sudo chown -R strong-pm:strong-pm /root/my_dir
sudo chmod -R 777 /root/my_dir
sudo chmod 777 /root/my_dir/file.txt
adding the strong-pm to a group
then adding that group to the directory...
Still no luck.. any ideas?
Thanks!
System: Ubuntu 14.04 x64 on DigitalOcean

Rather than trying it inside node, try to switch to that user and read the file:
su strong-pm
cat /root/my_dir/file.txt
If that works, make sure node is running using that user.

Try this:
.{otherPATH}/root/my_dir/file.txt

It seemed like the issue was that the /root directory was protected and so subdirectories were not accessible by node somehow

Related

Error: EACCES: permission denied NPM Ubuntu Server

I am running an Ubuntu EC2 server and followed the tutorial provided by AWS to install nvm and node, but when I try to run npm install, I'm thrown an error:
Error: EACCES: permission denied, access '/var/www/app'
Please try running this command again as root/Administrator.
The standard procedure with an EC2 Ubuntu service appears to only provide a ubuntu user with sudo privileges and no access to root so I tried to run sudo npm install, but I receive sudo: npm: command not found. The reason why I believe this is happening is because nvm is located at /home/ubuntu/.nvm/versions/node/v6.12.3/bin/node, which root might not have access to?
Is it possible to point root to the this directory location for this command or is there a different solution?
You're getting that error because you do not have write permission for your user on that /var/www/app.
You can follow the answer here to give permissions to that folder.
https://askubuntu.com/questions/749697/how-do-i-give-myself-access-to-var-www-to-create-and-edit-files-and-folders-in
You are getting the error about npm not being installed when you use sudo because it is not installed for the admin user. I would avoid installing node and npm through sudo though. Just go with changing the folder permissions.

yarn error "EACCESS: permission denied, scandir '/home/ubuntu/.config/yarn/link'"

Whenever I try something with yarn on Ubuntu 16.04 server.
It gives an error.
I am currently using nodejs v8.10.0
yarn install v1.5.1
error An unexpected error occurred: "EACCES: permission denied, scandir '/home/ubuntu/.config/yarn/link'".
info If you think this is a bug, please open a bug report with the information provided in "/home/ubuntu/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Anyone know why this is happening?
It's likely a unix permission related problem. There is a solution posted on the dev's github page. Try to run the following command
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
Reference: EACCES: permission denied .config/configstore/bower-github.json #2262
I had this problem as well, I found on another thread that my config folder was owned by root, which created several permissions issues.. I changed owner to my user and this error went away.
See top answer on this thread
Unable to access 'git/attributes'

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.
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/

Unable to create yeoman webapp

I get this when I try to create a webapp with yeoman.
/usr/local/lib/node_modules/yo/node_modules/insight/node_modules/configstore/configstore.js:66
throw err;
^
Error: EACCES, permission denied '/root/.config/configstore/insight-yo.yml'
You don't have access to this file.
at Object.fs.openSync (fs.js:436:18)
at Object.fs.writeFileSync (fs.js:975:15)
at Object.create.all.set (/usr/local/lib/node_modules/yo/node_modules/insight/node_modules/configstore/configstore.js:56:8)
at Object.Configstore (/usr/local/lib/node_modules/yo/node_modules/insight/node_modules/configstore/configstore.js:19:11)
at new Insight (/usr/local/lib/node_modules/yo/node_modules/insight/lib/insight.js:23:34)
at process.<anonymous> (/usr/local/lib/node_modules/yo/node_modules/insight/lib/push.js:11:16)
at process.emit (events.js:98:17)
at handleMessage (child_process.js:322:10)
at Pipe.channel.onread (child_process.js:349:11)
I googled and I tried the following things, but it didn't help:
chown root /root/.config/configstore/insight-yo.yml
chown myusername /root/.config/configstore/insight-yo.yml
Installed npm-sudo-fix and ran it, and no luck yet.
I am on Debian Wheezy and have npm 1.4.4.
I was facing the same issue. I ran the command below, It fixed my problem:
mkdir -p /root/.config/configstore
chmod g+rwx /root /root/.config /root/.config/configstore
The same issue happened to me, i was in root mode user#. I just get back to normal user$ and it worked. i am using Zorin OS
I was able to fix this by running:
echo prefix = ~/.node >> ~/.npmrc
and
export PATH=$HOME/.node/bin:$PATH
Explanation here:
Error installing yeoman
What does `echo prefix = ~/.node >> ~/.npmrc` mean?
npm / yeoman install generator-angular without sudo
I just fixed it in Windows. I have done three things, which one have fixed it I am not sure.
Run cmd prompt as administrator.
takeown /? this command is equivalent to chown (linux) but for windows.
cacls -cacls /E /T /G :F
simply go in $USER /Users/calvin/.config/configstore/ and make files unhidden.
it worked for me like charm. I have been trying to fix this since many days.
I had the same issue building a meanjs app on Ubuntu and I've fixed this issue using sudo instead of root:
sudo npm install -g yo generator-meanjs bower grunt
Then i could build the app without being asked for password again:
yo meanjs
sudo allows user to act as root without root login, it is more secure to use sudo instead of logging in as root.
sudo vs root - askubuntu
Although the chmod command seemed to work at first, I got a similar error later, for a different folder. But here I found this workaround which fixed that too:
sed -i -e '/rootCheck/d' "${NPM_CONFIG_PREFIX}/lib/node_modules/yo/lib/cli.js"
If yo is run as root, rootCheck will downgrade to UID 1000 (on Linux) or 501 (on OS X). This causes the permission error. But in a docker container, you might want to run as root, so you have no other option.
You need to rerun this command after upgrading yeoman. In case NPM_CONFIG_PREFIX is not defined, you can use:
export NPM_CONFIG_PREFIX=$(npm config get prefix)
the issue is that yo is not granted to use some of the nodejs modules. basically, y the problem is related to authorization of yo by node package manager "npm", to fix this run this command first
sudo npm install --global yo --allow-root

EACCES error using Yeoman to install angular

I tried running
yo angular --coffee --minsafe
but I get this error
Error: EACCES, permission denied '/Users/Basil/.config/configstore/insight-yo.yml'
at Object.fs.openSync (fs.js:427:18)
at Object.fs.writeFileSync (fs.js:966:15)
at Object.create.all.set (/usr/local/lib/node_modules/yo/node_modules/insight/node_modules/configstore/configstore.js:39:7)
at Object.Configstore (/usr/local/lib/node_modules/yo/node_modules/insight/node_modules/configstore/configstore.js:30:11)
at new Insight (/usr/local/lib/node_modules/yo/node_modules/insight/lib/insight.js:20:16)
at Object.<anonymous> (/usr/local/lib/node_modules/yo/bin/yo:26:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
I have checked the issues on Github and seen npm / yeoman install generator-angular without sudo but can't seem to get it to work
node v0.10.17
npm v1.2.10
find / -name 'yeoman'
/Users/Basil/.node/node_modules/.bin/yeoman
/Users/Basil/.node/node_modules/yeoman
/Users/Basil/.node/node_modules/yeoman/bin/yeoman
/Users/Basil/.node/node_modules/yeoman/node_modules/yeoman-generators/lib/generators/yeoman
/Users/Basil/.npm/yeoman
/Users/Basil/.npm/yeoman/0.9.6/package/bin/yeoman
/Users/Basil/.npm/yeoman-generators/0.9.5/package/lib/generators/yeoman
I was able to fix this issue with this:
Sudo chown Basil /Users/Basil/.config/configstore/update-notifier-yo.yml
If you run into this issue, try this out, replacing "Basil" with your username
You can just use npm cache clean and bower cache clean.
Sudo chown Basil /Users/Basil/.config/configstore/update-notifier-yo.yml (Remove trailing chown) Replace Basil with your username.
Sudo chown <yourusername> /Users/<yourusername>/.config/configstore/update-notifier-yo.yml Keepinging in mind your username does not include the dollar sign.
This corrected the Error when running Yeoman:
EACCES, permission denied '/Users/<yourusername>/.config/configstore/update-notifier-yo.yml'
If the above doesn't work simply delete all files in the /Users/USER_NAME/.config/configstore/ directory and run yo angular again. Replace USER_NAME with your user name.
I just fixed it in Windows.
I have done three things, which one have fixed it I am not sure.
Run cmd prompt as administrator.
takeown /? this command is equivalent to chown (linux) but for windows.
cacls -cacls /E /T /G :F
simply go in $USER /Users/calvin/.config/configstore/ and make files unhidden.
it worked for me like charm.
I have been trying to fix this since many days.
This is probably too late to answer but in order to help others, changing both permissions (chmod) and owner (chown) is what worked for me on Ubuntu:
sudo chmod g+rwx /home/myusername/.config/configstore
sudo chown myusername /home/myusername/.config/configstore
This one worked for me :
//Update npm to the latest version. Works for to upgrade 1.x to 2.x.
$ npm install -g npm stable
// Assign group permissions to the parent directory.
$ chmod g+rwx /root /root/.config /root/.config/configstore
you can simply remove the .config folder from user home directory
rm -rf /home/user/.config then run sudo yo which will create .config again and reset previous faulty configuration. Mine is working fine after apply this approach.

Resources