1

var express = require('express');
var app = express();
app.use('/', express.static('./'));
app.listen(80);

The error msg I receive in the cli via "node server.js" is: events.js:160 throw er; // Unhandled 'error' event ^

Error: listen EACCES 0.0.0.0:80 at Object.exports._errnoException (util.js:1018:11) at exports._exceptionWithHostPort (util.js:1041:20) at Server._listen2 (net.js:1245:19) at listen (net.js:1294:10) at Server.listen (net.js:1390:5) at EventEmitter.listen (G:\angular\node_modules\express\lib\application.js:618:24) at Object. (G:\angular\server.js:4:5) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32)

Any ideas why a simple bit of code would generate errors? I got the code from an older angularjs book I'm trying to learn from. Changes with node or express possibly?

1
  • You need to add the resource name as static route (eg. folder containing frontend code or html etc), not another route :) Commented Jul 2, 2017 at 19:55

3 Answers 3

1

On Unix, all ports below 1024 are so called Privileged Ports. Only root or other specific system users can start services here.

When you're programming with a regular user (as you should), it's customary to start your dev server on ports above 1024. For web servers it's common to use 8080 or 3000.

The error message Error: listen EACCES 0.0.0.0:80 also gave you a hint. EACCESS means that you do not have the rights to open a server on port 80. Only the root user does for running production code.

Also one piece of advice: AngularJS has changed a lot in the last years. So if you want to learn it, don't use an older book. Much of what you'd learn is probably obsolete and done differently now.

Sign up to request clarification or add additional context in comments.

2 Comments

This worked for me. just a simple change to another port made it work. 8080 is typically a port I use for serving local files but I thought I had already tried changing the port. Big Help! Also, I'm learning AngularJS not really nodejs but the book seems to be pushing a lot of node and express. Either way... Thanks for explanation and solution.
@Rogue33 Sure thing, happy to be of help^^ Enjoy learning Angular with some Node and Express along the way!
0

Error: listen EACCES means you don't have permission to listen on that port. Try different port.

And static content should be served like this

app.use(express.static(__dirname + '/'));

__dirname represent current directory.

Comments

-1

This code is working for me, please try it:

var express = require('express');

var app = express.createServer();

app.get('/', express.static(__dirname + 'your path'));

app.listen(80);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.