Running Meteor on localhost fails with RangeError: port should be >= 0 and < 65536: NaN

懵懂的女人 提交于 2019-12-13 10:30:33

问题


I am running a project on localhost using node and Mongodb, but it fails with an error as soon as I try to create a collection on the database.

I am building the project with this script:

cd ~/Meteor/daily-reminder
meteor build ~/build-output-daily-reminder --server=http://localhost
cd ~/build-output-daily-reminder
tar -xvzf daily-reminder.tar.gz
rm daily-reminder.tar.gz
cd ~/build-output-daily-reminder/bundle
(cd programs/server && npm install)
export MONGO_URL='mongodb://username:password@http://localhost:27017/daily-reminder'
export ROOT_URL='http://localhost/'
export PORT='3000'
echo "now run node main.js"
node main.js

(I use my actual mongodb username and password in the real code).

The project builds fine, but node won't run. It generates this error:

now run node main.js
/home/shelagh/build-output-daily-reminder/bundle/programs/server/node_modules/fibers/future.js:245
                        throw(ex);
                              ^
RangeError: port should be >= 0 and < 65536: NaN
    at Socket.connect (net.js:917:13)
    at Object.exports.connect.exports.createConnection (net.js:92:35)
    at [object Object].Connection.start (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/connection/connection.js:173:29)
    at _connect (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:211:16)
    at [object Object].ConnectionPool.start (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:231:3)
    at Server.connect (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/connection/server.js:708:18)
    at Db.open (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/db.js:281:23)
    at connectFunction (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/mongo_client.js:275:67)
    at Function.MongoClient.connect (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/mongo_client.js:345:5)
    at Function.Db.connect (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/db.js:2094:23)

If I use a newly-created Meteor project then node runs ok. But it fails as soon as I add this line to start of my js file:

Tasks = new Mongo.Collection("tasks");

It seems like there is some problem as soon as the server tries to communicate with the database. But I can't see anything wrong with my MONGO_URL: port is specified as 27017. From the error, it looks like the port isn't even being passed in.

I am using node v0.12.7 and MongoDB shell version: 2.4.9. I have started mongo by typing 'mongo' in a separate terminal window.


回答1:


Your MONGO_URL is wrong, it redefines the protocol where you specify the host.

Change

export MONGO_URL='mongodb://username:password@http://localhost:27017/daily-reminder'

to

export MONGO_URL='mongodb://username:password@localhost:27017/daily-reminder'


来源:https://stackoverflow.com/questions/31416096/running-meteor-on-localhost-fails-with-rangeerror-port-should-be-0-and-655

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!