使用nodejs和pm2时出现此错误:
connect [MongoError: getaddrinfo EMFILE localhost:27017]
0|app | at Pool.<anonymous> (/home/ride4youco/public_html/node_modules/mongodb-core/lib/topologies/server.js:336:35)
0|app | at emitOne (events.js:96:13)
0|app | at Pool.emit (events.js:188:7)
0|app | at Connection.<anonymous> (/home/ride4youco/public_html/node_modules/mongodb-core/lib/connection/pool.js:280:12)
0|app | at Connection.g (events.js:292:16)
0|app | at emitTwo (events.js:106:13)
0|app | at Connection.emit (events.js:191:7)
0|app | at Socket.<anonymous> (/home/ride4youco/public_html/node_modules/mongodb-core/lib/connection/connection.js:187:49)
0|app | at Socket.g (events.js:292:16)
0|app | at emitOne (events.js:96:13)
当我使用带有express和socket.io的节点时 也许有人知道是什么原因造成的?
这是app.js:
var express = require('express');
var app = express();
var server = require('http').createServer(app);
global.io = require('socket.io').listen(server);
var compression = require('compression');
var helmet = require('helmet');
var session = require('express-session');
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
app.use(express.static(__dirname + '/src/'));
app.use(helmet());
app.use(compression());
app.use('/rides', require('./routes/ridesServer'));
app.use('/user', require('./routes/userServer'));
app.use('/offers', require('./routes/offersServer'));
app.use('/notifications', require('./routes/notificationsServer'));
server.listen("8080", function() {
console.log("Connected to db and listening on port 8080");
});
一整个月都工作得非常好,当尝试使用重定向301或者一些新的套接字功能时,这种情况就开始发生了。 我说NEW,因为我已经使用套接字功能整整一个月,一切都很好..我也评论那些套接字线,这仍然无法正常工作..
我必须提到它会在5分钟后再次起作用,然后经过一段时间它将无法再次工作..
我也遇到了这个错误:
0|app | Error: EMFILE: too many open files, open '/home/ride4youco/public_html/src/fonts/open-sans/opensanshebrew-regular-webfont.woff'
答案 0 :(得分:0)
我在所有路由之前将此行添加到app.js:
var fs = require('graceful-fs');
事情又恢复了。希望它能保持这样。