在localhost上运行Meteor失败并出现RangeError:port应该是> = 0和< 65536:NaN

时间:2015-07-14 19:55:25

标签: mongodb meteor localhost

我正在使用node和Mongodb在localhost上运行一个项目,但是一旦我尝试在数据库上创建一个集合,它就会失败并出现错误。

我正在用这个脚本构建项目:

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

(我在实际代码中使用我的实际mongodb用户名和密码。)

该项目构建良好,但节点不会运行。它会生成此错误:

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)

如果我使用新创建的Meteor项目,那么节点运行正常。但是,只要我将这一行添加到我的js文件的开头,它就会失败:

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

一旦服务器尝试与数据库通信,似乎就会出现问题。但我无法看到我的MONGO_URL有什么问题:端口被指定为27017.从错误中看,端口似乎甚至没有被传入。

我使用的是节点v0.12.7和MongoDB shell版本:2.4.9。我已经通过输入“mongo”来开始使用mongo&#39;在一个单独的终端窗口。

1 个答案:

答案 0 :(得分:0)

您的MONGO_URL错误,它重新定义了您指定主机的协议。

更改

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

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