node.js 在 linux 上运行节点(express)产生错误:产生 EACCES
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19009778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running node (express) on linux produces Error: spawn EACCES
提问by jansmolders86
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).
我正在使用 Expressjs 构建一个节点应用程序,我正在尝试在新安装的 Ubuntu 上运行我的节点应用程序(我刚刚安装了 git 和 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.
我在端口 3000 上运行,并且正在使用 sudo。我也以 root 身份尝试过,并且还尝试了 1024 阈值以上的不同端口。
The app is just basic Expressjs and I'm using the default method for opening the app socket:
该应用程序只是基本的 Expressjs,我使用默认方法打开应用程序套接字:
app.listen(3000);
I'm a Linux noob so any help is appreciated. the app works just great on Windows by the way.
我是 Linux 菜鸟,因此感谢您的任何帮助。顺便说一下,该应用程序在 Windows 上运行良好。
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
您可以通过安装自己测试: npm install mediacenterjs
回答by jansmolders86
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

