19

Everything was worked fine before today evening after i uninstalled vscode and installed again I'm facing this issue while try to run npm run app i have no clue how to fix this i tried to run vs code and command prompt or bash using run as administrator but no luck, i see lot of fixes out there for this issue but most of them are for mac they fixed it using sudo but i don't see any good fix for windows it would be appreciated much if anyone will help me fix this

//this issue this my server code 
const express = require("express");
const app = express()
const port = process.env || 8080

app.get("/", (req, res) => {
  res.send("Hello");
});



app.listen(port,()=>{
  console.log("running on 8080")
})

and this is the complete error

events.js:187
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES: permission denied C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\BookStore\node_modules\.bin;C:\Users\Samarth's PC\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Samarth's PC\bin;C:\ProgramData\Miniconda3;C:\ProgramData\Miniconda3\Library\mingw-w64\bin;C:\ProgramData\Miniconda3\Library\usr\bin;C:\ProgramData\Miniconda3\Library\bin;C:\ProgramData\Miniconda3\Scripts;C:\Python27;C:\Python27\Scripts;C:\Users\Samarth's PC\AppData\Local\Programs\Python\Python38-32\python.exe;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\Yarn\bin;C:\Users\Samarth's PC\AppData\Local\Microsoft\WindowsApps;C:\Program Files\MongoDB\Server\4.0\bin;C:\Program Files\heroku\bin;C:\nvm;C:\Program Files\nodejs;C:\Python 3.8;C:\Users\Samarth's PC\AppData\Roaming\npm;C:\Users\Samarth's PC\AppData\Local\Yarn\bin;C:\Users\Samarth's PC\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
    at Server.setupListenHandle [as _listen2] (net.js:1283:19)
    at listenInCluster (net.js:1348:12)
    at Server.listen (net.js:1447:5)
    at Function.listen (D:\BookStore\node_modules\express\lib\application.js:618:24)
    at Object.<anonymous> (D:\BookStore\app.js:11:5)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1327:8)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'EACCES',
  errno: 'EACCES',
  syscall: 'listen',
  address: "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\npm-lifecycle\\node-gyp-bin;D:\\BookStore\\node_modules\\.bin;C:\\Users\\Samarth's PC\\bin;C:\\Program Files\\Git\\mingw64\\bin;C:\\Program Files\\Git\\usr\\local\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Program Files\\Git\\mingw64\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Users\\Samarth's PC\\bin;C:\\ProgramData\\Miniconda3;C:\\ProgramData\\Miniconda3\\Library\\mingw-w64\\bin;C:\\ProgramData\\Miniconda3\\Library\\usr\\bin;C:\\ProgramData\\Miniconda3\\Library\\bin;C:\\ProgramData\\Miniconda3\\Scripts;C:\\Python27;C:\\Python27\\Scripts;C:\\Users\\Samarth's PC\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe;C:\\Program Files\\nodejs;C:\\ProgramData\\chocolatey\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0;C:\\WINDOWS\\System32\\OpenSSH;C:\\Program Files (x86)\\Yarn\\bin;C:\\Users\\Samarth's PC\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files\\MongoDB\\Server\\4.0\\bin;C:\\Program Files\\heroku\\bin;C:\\nvm;C:\\Program Files\\nodejs;C:\\Python 3.8;C:\\Users\\Samarth's PC\\AppData\\Roaming\\npm;C:\\Users\\Samarth's PC\\AppData\\Local\\Yarn\\bin;C:\\Users\\Samarth's PC\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files\\Git\\usr\\bin\\vendor_perl;C:\\Program Files\\Git\\usr\\bin\\core_perl",
  port: -1
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bookstore@1.0.0 start: `node app.js "app"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bookstore@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Samarth's PC\AppData\Roaming\npm-cache\_logs\2019-12-20T16_43_00_131Z-debug.log
//Error log is here
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'start',
1 verbose cli   'app'
1 verbose cli ]
2 info using npm@6.12.0
3 info using node@v12.13.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle bookstore@1.0.0~prestart: bookstore@1.0.0
6 info lifecycle bookstore@1.0.0~start: bookstore@1.0.0
7 verbose lifecycle bookstore@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle bookstore@1.0.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\BookStore\node_modules\.bin;C:\Users\Samarth's PC\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Samarth's PC\bin;C:\ProgramData\Miniconda3;C:\ProgramData\Miniconda3\Library\mingw-w64\bin;C:\ProgramData\Miniconda3\Library\usr\bin;C:\ProgramData\Miniconda3\Library\bin;C:\ProgramData\Miniconda3\Scripts;C:\Python27;C:\Python27\Scripts;C:\Users\Samarth's PC\AppData\Local\Programs\Python\Python38-32\python.exe;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\Yarn\bin;C:\Users\Samarth's PC\AppData\Local\Microsoft\WindowsApps;C:\Program Files\MongoDB\Server\4.0\bin;C:\Program Files\heroku\bin;C:\nvm;C:\Program Files\nodejs;C:\Python 3.8;C:\Users\Samarth's PC\AppData\Roaming\npm;C:\Users\Samarth's PC\AppData\Local\Yarn\bin;C:\Users\Samarth's PC\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
9 verbose lifecycle bookstore@1.0.0~start: CWD: D:\BookStore
10 silly lifecycle bookstore@1.0.0~start: Args: [ '/d /s /c', 'node app.js "app"' ]
11 silly lifecycle bookstore@1.0.0~start: Returned: code: 1  signal: null
12 info lifecycle bookstore@1.0.0~start: Failed to exec start script
13 verbose stack Error: bookstore@1.0.0 start: `node app.js "app"`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:210:5)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:210:5)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid bookstore@1.0.0
15 verbose cwd D:\BookStore
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" "app"
18 verbose node v12.13.0
19 verbose npm  v6.12.0
20 error code ELIFECYCLE
21 error errno 1
22 error bookstore@1.0.0 start: `node app.js "app"`
22 error Exit status 1
23 error Failed at the bookstore@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Hashim aslam
  • 243
  • 1
  • 2
  • 7
  • Is there any chance you can paste the error log at C:\Users\Samarth's PC\AppData\Roaming\npm-cache\_logs\2019-12-20T16_43_00_131Z-debug.log as well? – Zhephard Dec 20 '19 at 17:08
  • I've added the error log also please check @Zhephard – Hashim aslam Dec 20 '19 at 17:21
  • Are you missing the package.json file? Did you check npm -v or node -v? – Zhephard Dec 20 '19 at 17:25
  • i've checked npm and node version both are in updated versions and yes i've package.json file i see this error is because of some permission issue – Hashim aslam Dec 20 '19 at 17:33
  • Consider changing the tags for the question as this doesn't imply something to do with node.js or npm, but OS permission management – Zhephard Dec 20 '19 at 17:38
  • it may be but people who have experience in working with node might have a higher chance to give solution this is a very popular issue but unfortunately i didn't get any good and clear fix for this issue especially in windows ,anyways i'll add some extra tags ,Do you know some kind of similar thing for windows like sudo in mac ? @Zhephard – Hashim aslam Dec 20 '19 at 17:41
  • Use this reference maybe https://stackoverflow.com/questions/9652720/how-to-run-sudo-command-in-windows – Zhephard Dec 20 '19 at 17:55

14 Answers14

106

Hi anyone who comes here and don't find any answer. I have an answer that I think will help. it fixed the issue for me. there is cases where nothing is running on the port but some applications or even your code can not run the fix to this is in this order:

  1. Open PowerShell as Admin.

  2. stop winnat with command below:

$ net stop winnat
  1. start winnat again with command below:
$ net start winnat

this fixed the problem for me in many cases. no restart needed. I hope it will help you too.

Edit: I dig in the problem and found out the problem is the port isn't closed in the right way that could be caused easily based on killing the terminal window or the app running on the port.

DevAddict
  • 1,583
  • 1
  • 10
  • 17
10

For my case in the env file, I added a semicolon that wasn't supposed to be added I had written

PORT=5000;

instead of

PORT=5000
5

For me this is constantly happening when Windows 10 has some pending updates. To fix this i need to install all pending updates and reboot 1-2 times during the process.

Kshatra
  • 369
  • 1
  • 4
  • 12
2

Error: listen EACCES: permission denied

This might be happening because port or your localhost is running some other application on it. One possible error people didn't answer here is an active IIS server in your local computer. In my case, this was the source of error. So I stopped IIS server to free that localhost and it worked for me. In case anyone's facing this problem you may try this option.

1

I found that putting semicolon in .env file is making the problem. Now, I fixed it. Thanks

Sahidul Islam
  • 53
  • 2
  • 10
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 27 '22 at 15:38
1

As in my case, I'd like to leave comments during coding so before this was my line in .env file PORT=5000// starting port of server

But then I removed the comment and I don't have this problem again

My line looks like this

PORT=5000

The reason is .env file is not a javascript file but a text file. So when using variable from .env file it first considered the port number as '5000// starting port of server' So in .env file we have to keep the attribute and the value only

Cheers

0

I solved this doing these steps:

Always using administrative previlegies

And it will work

0

I've disabled the anti-virus real-time-protection and it has been fixed.

MTM
  • 113
  • 1
  • 8
0

I have faced the same issue. Some windows application running on the background or perhaps a process that you have started on your own is using the port that you want to listen at. Try to use a random port number. For example 5645. If you do not get it working after 2 or 3 attempts you can be sure that the problem is not caused because of the port being used.

Nick
  • 181
  • 2
  • 11
0

for me, I had to remove all lock files (yarn.lock or package-lock.json) and node_modules folder. I actually couldn't remove normally the node_module folder so I open Powershell as admin in the directory and run rm node_modulesand confirmed. after that, I run yarn install(it would work same with npm) successfully.

Eliav Louski
  • 3,593
  • 2
  • 28
  • 52
0

In case it helps someone else, it was failing for me because I tried adding a port that was too small (999), try changing your port and see if it can be solved that way.

Shadoweb
  • 5,812
  • 1
  • 42
  • 55
0

I have seen multiple solutions in the internet but its a very simple mistake that I have done.

In the .env file I have wrote the port number like,

PORT = 5000;

but it should be like

PORT = 5000

No semicolon ; at the end in the .env file

-1

In this particular case, it fails because in your code port isn't what you think it is. See, process.env is an object with your environment variables, not the port number.

So instead of

const port = process.env || 8080

It should be something like

const port = process.env.PORT || 8080

I figured because I inverted port and host arguments in app.listen(PORT, HOST, callback) and found this question while searching why it was failing to start with message Error: listen EACCES: permission denied localhost.

Willian Balmant
  • 167
  • 1
  • 3
-3

Try this steps

  • Run your command prompt / powershell as administrator before running this script
  • Remove node_modules folder completely & reinstall dependencies using npm install & then run start script
Sarfraaz
  • 1,273
  • 4
  • 15