linux下node开发笔记(1)

环境:ubuntu12.04 desktop    nodejs 4.4.3

代码如下:

var express = require('express');

var app = express();

var path = require('path');

app.use(require('body-parser').urlencoded({extended: true}));

app.use(express.static(path.join(__dirname, 'html/')));

app.listen(80, '127.0.0.1', 50, function(){
	console.log('listen ono port : 80');
});


会遭遇如下错误:

kean@ubuntu:~/Desktop/communityserver$ node app.js 
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES 127.0.0.1:80
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at Server._listen2 (net.js:1221:19)
    at listen (net.js:1270:10)
    at net.js:1379:9
    at nextTickCallbackWith3Args (node.js:453:9)
    at process._tickCallback (node.js:359:17)
    at Function.Module.runMain (module.js:443:11)
    at startup (node.js:139:18)
    at node.js:968:3

这个问题是由80端口没有访问权限引起的,将端口改为其他>1024的端口就可以了,或者切换到root用户执行

猜你喜欢

转载自becomebetter.iteye.com/blog/2295989
今日推荐