'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]

  1. Type cmd on your start menu

  2. Right click on the "Command Prompt" menu item and select "Open file Location"

  3. Right click on the file and select properties.

  4. Go to "Advanced" and select "Run as Administrator" and Ok.

enter image description here

If this doesn't solve your problem -

  1. Go to the "Security" tab.

  2. Click "Edit"

  3. Add "Everyone" and Ok

enter image description here

Solution 3:[3]

The fastest way that worked for me (Windows 10) was the following:

  1. Open "nodejs" folder location
  2. Right-click + R
  3. Open "Security tab" + "Advanced"
  4. Change Owner to "Administrator".
  5. Add permissions for Administrator "Full control"
  6. Tick "Replace all child objects permission entries..."
  7. "Ok". Save

? Done

Solution 4:[4]

use command prompt instead of powershell in windows 10

enter image description here

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