2016-03-21 137 views
0

現在在nodejs中進行培訓,以及如何使用nodejs和expressjs作爲框架開發MVC應用程序。我有TDD方法以及與TDD測試腳本一起編寫的Model和View類。我有一個MongoDB的測試腳本,也未能與以下錯誤信息:用茉莉花節點作爲測試包連接錯誤(錯誤) - 在expressjs框架中使用nodejs的Mongodb連接

expressjs_multech_project mul$ jasmine-node ./tests 
.......F 

Failures: 

    1) MongoDB is there a server running? 
    Message: 
    Expected { } to be null. 
    Stacktrace: 
    Error: Expected { } to be null. 
    at /Users/.../expressjs_multech_project/tests/mongodb.spec.js:6:19 
    at /Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/mongo_client.js:334:20 
    at /Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/db.js:258:16 
    at null.<anonymous> (/Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/connection/server.js:621:7) 
    at emitThree (events.js:110:13) 
    at emit (events.js:188:7) 
    at null.<anonymous> (/Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:139:15) 
    at emitTwo (events.js:100:13) 

Finished in 0.182 seconds 
8 tests, 18 assertions, 1 failure, 0 skipped 

Im和其他所有測試都通過了與剛剛寫入的模型和視圖類。我不明白爲什麼我的MongoDB的TDD腳本失敗有關MongoDB,當我npm start,它不會開始返回的app.js錯誤消息:

> node app.js 

Sorry, the server (mongodb) is not running 

我研究後面的堆棧跟蹤,並從我所看到的,與mongodb沒有聯繫,並且返回null。我檢查MongoDB中,以確保它的存在:

Johns-MacBook-Pro:expressjs_multech_project mul$ npm list mongodb 
[email protected] /Users/.../expressjs_multech_project 
└── [email protected] 

我已經試過配發的補救措施,但沒有最新的工作。關於解決與服務器連接問題的任何想法,所以我可以繼續這個expressjs MVC培訓項目?

我的配置/ index.js看起來是這樣的:

var config = { 
    local: { 
     mode: 'local', 
     port: 3000, 
     mongo: { 
     host: '127.0.0.1', 
     port: 27017 
     } 
    }, 
    staging: { 
     mode: 'staging', 
     port: 4000, 
     mongo: { 
     host: '127.0.0.1', 
     port: 27017 
     } 
    }, 
    production: { 
     mode: 'production', 
     port: 5000, 
     mongo: { 
     host: '127.0.0.1', 
     port: 27017 
     } 
    } 
} 
module.exports = function(mode) { 
    //export module configuration making it available to all files in folder 
    return config[mode || process.argv[2] || 'local'] || config.local; 

這是我當我充實了package.json文件。OUPUTS和npm install mongodb --savenpm install

muls-MacBook-Pro:expressjs_multech_project jmulhall$ npm install mongodb --save 

> [email protected] install /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project/node_modules/kerberos 
> (node-gyp rebuild 2> builderror.log) || (exit 0) 

    CXX(target) Release/obj.target/kerberos/lib/kerberos.o 

> [email protected] install /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project/node_modules/bson 
> (node-gyp rebuild 2> builderror.log) || (exit 0) 

    CXX(target) Release/obj.target/bson/ext/bson.o 
[email protected] /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project 
├─┬ [email protected] 
│ └─┬ [email protected] 
│ └─┬ [email protected] 
│  └─┬ [email protected] 
│  └─┬ [email protected] 
│   └── [email protected] 
└─┬ [email protected] 
    ├─┬ [email protected] 
    │ └── [email protected] 
    ├── [email protected] 
    └─┬ [email protected] 
    └── [email protected] 

由於運行安裝蒙戈...

+0

嗨約翰這不是從信息清楚,如果你已驗證您的mongo服務器已啓動。你是在本地還是從服務提供商運行mongodb? –

+0

嗨9,它的本地運行在127.0.0.1:27017 –

+0

9,我運行了npm start並且啓動失敗,這是我驗證mongdb服務器驗證的基礎。 –

回答

1

這看起來不像安裝時的錯誤,因爲組件返回exit 0這很好。

需要明確的是,雖然您正在安裝的軟件包是唯一的官方MongoDB的驅動https://www.npmjs.com/package/mongodb - The official MongoDB driver for Node.js. Provides a high-level API on top of mongodb-core that is meant for end users.

您需要安裝MongoDB服務器有一個完整的安裝https://docs.mongodb.org/manual/installation/

+0

偉大的東西數量9 ...我已經修復了..但是在學習了關於mongodb及其安裝的加載之後,我沒有修復它。我是一個釀造迷,但這次釀造的額外產品似乎會導致更糟糕的安裝。 –

+0

我發現了一篇非常清晰的安裝博客文章,並遵循它,現在正在我的本地計算機上工作(Mac OSX 10.11.4)。我還在我的MVC應用程序上運行了TDD測試,並且通過了所有測試,包括昨天我檢查了大約一千次的mongodb測試腳本!用於手動安裝的博客/教程的鏈接是http://www.mkyong.com/mongodb/how-to-install-mongodb-on-mac-os-x/ ...我會說我發現nano比較容易然後vim,所以我用nano來更新我的bash_profile。手動安裝的魅力。謝謝先生你的幫助和投入......你是男人之間的王! –