-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EACCES error when trying to run "node index.js" from CMD #1159
Comments
try a higher port please, say a 5 digit number. |
sorry, I did not look at your code. the listen takes port number as its first param: So please try this code: const http = require('http');
const hostname = 'localhost';
const port = 3000;
const server = http.createServer((req, res) => {
res.end('Welcome to Node!');
});
server.listen(port, () => {
console.log(`server listening on host: ${hostname} port: ${port}`);
}); |
Thanks. That looks like it did the trick! |
Hello, firstly thanks to @gireeshpunathil . this solved by issue too. Thank You. |
signature of server.listen([port][, host][, backlog][, callback]) for TCP servers port: optional, default is an arbitrary port from the OS The problematic code had port and host order reversed: server.listen(hostname, port, () => {
console.log('server listening on host: ${hostname} port: ${port}');
}); the problem is fixed by placing them in the right order. |
C:\Users\Phil\Documents\node\new_project>node index.js
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EACCES localhost
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at Server.setupListenHandle [as _listen2] (net.js:1350:19)
at listenInCluster (net.js:1408:12)
at Server.listen (net.js:1503:5)
at Object. (C:\Users\Phil\Documents\node\new_project\index.js:9:8)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
index.js source code if it helps.
The text was updated successfully, but these errors were encountered: