19

I'm building a node app with using Expressjs and I'm trying to run my node app on a freshly installed Ubuntu (I just installed git and node v 0.10.19).

Sadly though, I'm getting the following error when trying to run the app in terminal:

 Events.js:72
    throw er; // unhandled 'error' event

Error: spawn EACCES

I'm running on port 3000 and I am using sudo. I also tried as root and I also played around with different ports above the 1024 threshold.

The app is just basic Expressjs and I'm using the default method for opening the app socket:

  app.listen(3000);

I'm a Linux noob so any help is appreciated. the app works just great on Windows by the way.

The basic server code:

    var express = require('express')
    , app = express()
    , fs = require ('fs')
    , lingua = require('lingua');

    process.env.NODE_ENV = 'development';

    app.configure(function(){
        app.set('view engine', 'jade');
        app.set('views', __dirname + '/views');
        app.setMaxListeners(100);
        app.use(express.bodyParser());
        app.use(express.methodOverride());
        app.use(express.static(__dirname + '/public'));
        app.use(express.favicon(__dirname + '/public/core/favicon.ico'));
        app.use(lingua(app, {
            defaultLocale: 'translation_',
            storageKey: 'lang',
            path: __dirname+'/public/translations/',
            cookieOptions: {
                httpOnly: false,        
                expires: new Date(Date.now(-1)),  
                secure: false
            }
        }));
        app.use(app.router);
        app.locals.pretty = true;
    });

    app.configure('development', function(){   
        app.enable('verbose errors');
        app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));  
    });

    app.configure('production', function(){
        app.disable('verbose errors');
        app.use(express.errorHandler()); 
    });   

    require('./lib/routing/routing')(app,{ verbose: !module.parent });


    app.listen(3000);

You can test it out yourself by installing: npm install mediacenterjs

8
  • does it still happen with require(http).createServer(app).listen(3000)
    – Plato
    Sep 25, 2013 at 16:15
  • Testing it now :) One moment please! Sep 25, 2013 at 16:19
  • oh sorry i forgot quotes. i can't edit my previous comment anymore but it should read: require('http').createServer(app).listen(3000). you dont need to install http, its built in.
    – Plato
    Sep 25, 2013 at 16:20
  • Thanks but the error remains saldy. Sep 25, 2013 at 16:23
  • Damn! My only other guess is that you aren't actually running it as root. Are you doing sudo node app.js? Does sudo touch /etc/foo.test create a file /etc/foo.test without a permissions problem?
    – Plato
    Sep 25, 2013 at 16:27

1 Answer 1

27

I solved it by setting the file permissions correctly.

It works by settings read/write and execute permissions.

  sudo chmod -R a+rwx APPNAME/file
5
  • Fixed my problem with eaccess error 3 on file writes. Read worked perfectly but the permissions on the folders up the chain were not correct.
    – gspatel
    Dec 3, 2013 at 21:13
  • 5
    While this might fix an issue, it also makes APPNAME WRITABLE to everyone, which on servers is a HUGE security risk.
    – gerasalus
    Feb 14, 2014 at 13:43
  • 1
    @gerasalus, you are right, I changed my answer to setting the rights of just the file. Which also worked just fine. Thanks! Mar 12, 2014 at 8:31
  • 4
    Write permission is not necessary. You only need chmod a+x /path/to/file
    – chepukha
    Dec 16, 2014 at 18:08
  • giving writable access to anyone even for one file is still security risk
    – laimison
    Jun 14, 2020 at 18:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.