'Node.js: "Access is denied"
I'm trying to make a simple node.js app in VS Code. All im trying to do is:
const name = "Tom";
console.log("Hello " + name);
When I run the code, I get the error: Program 'node.exe' failed to run: Access is denied
.
When I try to check Node is installed with node -v
in windows cmd, it also says "Access is denied".
How do I fix this issue?
Solution 1:[1]
You don't have enough permission to execute node commands in CMD, to solve this
Run CMD
as an Admin
Solution 2:[2]
Type cmd on your start menu
Right click on the "Command Prompt" menu item and select "Open file Location"
Right click on the file and select properties.
Go to "Advanced" and select "Run as Administrator" and Ok.
If this doesn't solve your problem -
Go to the "Security" tab.
Click "Edit"
Add "Everyone" and Ok
Solution 3:[3]
The fastest way that worked for me (Windows 10) was the following:
- Open "nodejs" folder location
- Right-click + R
- Open "Security tab" + "Advanced"
- Change Owner to "Administrator".
- Add permissions for Administrator "Full control"
- Tick "Replace all child objects permission entries..."
- "Ok". Save
? Done
Solution 4:[4]
Solution 5:[5]
Add "cd" before your directory name in cmd.
Ex: cd C:\Users..\js folder name(not the filename)
and then type "dir" in cmd.
Ex: dir
you will get a list of files present in that folder,And then just enter "node jsfilename"
[Ex][2]: node jsfilename
now you will have the desired output in cmd.
I think Access Denied happened because your root directory was different than the file's root directory that's why we used "cd" change directory, and to view the files present in the current directory we used "dir". Then we opened the js file with node "node jsfilename".I hope You Got it.I believe you can see the image I have Attached below.
Refer To this image below:
https://i.stack.imgur.com/oibrF.jpg
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Shivam |
Solution 2 | Charlie |
Solution 3 | ok.alex |
Solution 4 | Suraj Rao |
Solution 5 |