节点JS给我这个错误,
public static void main(String []) {
Derived bObj = new Derived();
bObj.staticMethod(bObj);
}
这似乎是SO上的一个非常常见的错误,但事实是该应用仍然可以工作,尽管抛出了这个错误,最后一行说应用程序崩溃了。此外,此错误并不总是抛出。
这是我非常简单的events.js:136
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000
at Object._errnoException (util.js:999:13)
at _exceptionWithHostPort (util.js:1020:20)
at Server.setupListenHandle [as _listen2] (net.js:1379:14)
at listenInCluster (net.js:1420:12)
at Server.listen (net.js:1508:7)
at Function.listen (/opt/bitnami/apps/direcDem/node_modules/express/lib/application.js:618:24)
at MongoClient.connect (/opt/bitnami/apps/direcDem/server.js:16:6)
at connectCallback (/opt/bitnami/apps/direcDem/node_modules/mongodb/lib/mongo_client.js:314:5)
at /opt/bitnami/apps/direcDem/node_modules/mongodb/lib/mongo_client.js:252:13
at process._tickCallback (internal/process/next_tick.js:150:11)
[nodemon] app crashed - waiting for file changes before starting...
:
server.js
我认为错误与我正在使用的Mongo数据库有关,但我不确定问题是什么。 CRUD操作仍然有效,所以我不知道出了什么问题。
错误有问题,因为
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const bodyParser = require('body-parser');
const db = require('./config/db');
const app = express();
const port = 3000;
app.use(bodyParser.urlencoded({ extended: true }));
MongoClient.connect(db.url, (error, database) => {
if (error) return console.log(error)
require('./app/routes')(app, database);
app.listen(port, () => {});
})
s 为什么会发生此错误,我该如何解决?