RangeError [ERR_SOCKET_BAD_PORT]: Port should be >= 0 and < 65536. Received NaN
Asked Answered
S

3

11

I am using Ubuntu 18.04 I was trying to run npm by "npm start". I am getting the above error. Anyone help me in resolving this error.

`

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)
`

Below is my env file:

`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`
Shopping answered 15/4, 2019 at 14:24 Comment(1)
I have the same error on windows 10Rahmann
I
8

first ensure about your .env and its initializing, this problem caused of not providing the redis_host or redis_url or redis_port, etc...

so we should take the following steps:

  1. Make sure about .env file
  2. load from .env
  3. make sure about set the variables correctly
Irrefutable answered 3/3, 2021 at 18:26 Comment(0)
R
0

I was helped by adding to Heroku -> MyApp -> Settings -> Config Vars -> REDIS_PORT: 5003. I also specified this port in the .env file.

Rahmann answered 17/3, 2022 at 15:43 Comment(0)
M
0

You must validate that you have placed the .env file in the correct directory location.

In my case I used the .env file in the folder before the .dist folder

enter image description here

Murton answered 26/11, 2022 at 5:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.