【发布时间】:2019-07-07 10:35:42
【问题描述】:
我已按照 traversy 媒体教程在数字海洋上部署 nodejs 应用程序。我正在使用数字海洋的 postgres 数据库。但是在运行node app.js 命令时出现错误
我尝试在stackoverflow上关注很多答案,但他们没有解决问题
app.js
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const morgan = require('morgan')
const db = require('./queries') // contains all query functions
const port = 3000
const app = express()
app.use(morgan('combined'))
app.use(bodyParser.json())
app.use(
bodyParser.urlencoded({
extended: true,
})
)
app.use(cors())
app.get('/runs', db.getPlayers)
app.post('/year', db.getByYear)
//Handle production
app.use(express.static(__dirname+'/public/'))
//Handle SPA
app.get(/.*/, (request, response) => response.sendFile(__dirname+'/public/index.html') );
app.listen(port, () => {
console.log(`App running on port ${port}.`)
})
我得到的错误是:-
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at Server.setupListenHandle [as _listen2] (net.js:1367:14)
at listenInCluster (net.js:1408:12)
at Server.listen (net.js:1492:7)
at Function.listen (/home/vineet/IPL-Stats-Analysis-Dashboard/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/vineet/IPL-Stats-Analysis-Dashboard/app.js:63:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
【问题讨论】:
-
我认为 madflow 可能是对的,但我要问你 Vineet,你有没有测试过这个应用程序?始终在整个过程中测试您的应用程序,尤其是那些只会催促您完成应用程序创建的教程,而无需彻底了解您在做什么以及为什么这样做。
标签: node.js digital-ocean