我正在使用Ubuntu 18.04,我试图通过“npm start”运行npm。我得到了上面的错误。任何人都可以帮助我解决这个错误。
`
WARNING: Adonis has detected an unhandled promise rejection, which may
cause undesired behavior in production.
To stop this warning, use catch() on promises or wrap await
calls inside try/catch.
RangeError [ERR_SOCKET_BAD_PORT]: Port should be >= 0 and < 65536. Received NaN.
at lookupAndConnect (net.js:938:13)
at Socket.connect (net.js:914:5)
at Object.connect (net.js:162:17)
at makeConnection (/home/bhagya/foodmonk/node_modules/mongodb-core/lib/connection/connect.js:270:20)
at makeConnection (/home/bhagya/foodmonk/node_modules/mongodb-core/lib/connection/connect.js:36:7)
at callback (/home/bhagya/foodmonk/node_modules/mongodb-core/lib/connection/connect.js:260:5)
at makeConnection (/home/bhagya/foodmonk/node_modules/mongodb-core/lib/connection/connect.js:273:12)
at connect (/home/bhagya/foodmonk/node_modules/mongodb-core/lib/connection/connect.js:34:10)
at Pool.connect (/home/bhagya/foodmonk/node_modules/mongodb-core/lib/connection/pool.js:548:3)
at Server.connect (/home/bhagya/foodmonk/node_modules/mongodb-core/lib/topologies/server.js:498:15)
at Server.connect (/home/bhagya/foodmonk/node_modules/mongoose/node_modules/mongodb/lib/topologies/server.js:360:25)
at createServer (/home/bhagya/foodmonk/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:350:10)
at parseFn (/home/bhagya/foodmonk/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:245:14)
at parseHandler (/home/bhagya/foodmonk/node_modules/mongoose/node_modules/mongodb/lib/url_parser.js:134:38)
at module.exports (/home/bhagya/foodmonk/node_modules/mongoose/node_modules/mongodb/lib/url_parser.js:25:12)
at deprecated (internal/util.js:71:15)
`
下面是我的env文件:
`HOST=127.0.0.1
PORT=3333
NODE_ENV=development
APP_URL=http://${HOST}:${PORT}
CACHE_VIEWS=false
APP_KEY=xyavbcd
SESSION_DRIVER=cookie
HASH_DRIVER=bcrypt
DB_CONNECTION=mongodb
MONGO_HOST=localhost
MONGO_PORT=27017
MONGO_USER=
MONGO_PASSWORD=
MONGO_DATABASE=xyz`
3条答案
按热度按时间bq3bfh9z1#
首先确认一下你的
.env
和它的初始化,这个问题是由于没有提供redis_host或者redis_url或者redis_port等等引起的。因此,我们应采取以下措施:
1.确保.env文件
1.从.env加载
1.确保正确设置变量
lztngnrs2#
我通过添加到Heroku -〉MyApp -〉设置-〉配置变量-〉REDIS_PORT得到了帮助:5003。我还在.env文件中指定了此端口。
watbbzwu3#
必须验证是否已将. env文件放置在正确的目录位置。
在我的示例中,我使用了. dist文件夹之前的文件夹中的. env文件
enter image description here