Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
117 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...