[英]Server doesn't start
Today I try open my server, but it doesn't start今天我尝试打开我的服务器,但它没有启动
Full code - https://github.com/meln1337/error-proxy完整代码 - https://github.com/meln1337/error-proxy
app.js应用程序.js
const express = require('express')
const config = require('config')
const mongoose = require('mongoose')
const app = express()
app.use(express.json({extended: true}))
app.use('/api/auth', require('./routes/auth.routes'))
const PORT = config.get('port') || 5000
async function start () {
try {
await mongoose.connect('mongodb+srv://borys:1q2w3e4r5t6y7u8i@cluster0-puuhz.mongodb.net/app', {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
})
app.listen(PORT, () => {
console.log(`App has been started on port ${PORT}...`)
})
} catch (e) {
console.log('Server error', e.message)
process.exit(1)
}
}
start()
config/default.json配置/默认.json
{
"port": 5000
}
Does the server not start due to mongodb?是不是因为mongodb导致服务器没有启动? If not then why does the server not start?
如果不是那么为什么服务器不启动?
I was able to run it, locally, with a few changes to "remove" missing files (ie, changing your mongodb uri to a localhost thingy).我能够在本地运行它,并进行一些更改以“删除”丢失的文件(即将您的 mongodb uri 更改为 localhost 的东西)。
Have you checked your console?你检查过你的控制台吗? When I run it, I get (assuming I have
config
), TypeError: config.get is not a function
.当我运行它时,我得到(假设我有
config
), TypeError: config.get is not a function
。 So unless I'm missing something, that's your first issue.所以除非我遗漏了什么,否则这是你的第一个问题。
The second is that, for me, obviously the Mongodb instance won't work.第二个是,对我来说,显然 Mongodb 实例不起作用。 I assume that's not true for you - you don't get
error querySrv ENODATA
- but that's worth checking too.我认为这对你来说不是真的 - 你不会得到
error querySrv ENODATA
- 但这也值得检查。
Finally, if your question is still about mongodb, why not remove that?最后,如果您的问题仍然是关于 mongodb,为什么不删除它呢? Just comment out the
await...
bit, and see if the server starts?只需注释掉
await...
位,然后查看服务器是否启动?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.