大家好:)我的問題是不工作response.vrite() 爲什麼? 還有另一個問題。將被稱爲db.open每個啓動/升級頁面?節點js上的簡單服務器
var http = require("http");
var Db = require ("mongodb").Db;
var Server = require("mongodb").Server;
function start() {
'use strict';
function onRequest (request, response) {
'use strict';
var db = new Db ("TestApp", new Server ("127.0.0.1", 27017, {}));
response.writeHead(200, {"Content-Type": "application/json", "Access-Control-Allow-Origin": "*"});
db.open (function (err, db, response) {
db.collection ('ObjectCollection', function (err, collection) {
collection.find().toArray (function (err, docs) {
console.log (docs);
response.write(JSON.stringify(docs));
});
});
});
response.end();
}
http.createServer(onRequest).listen(8080);
console.log ('Server has started...')
}exports.start = start;
您是否檢查控制檯正在打印什麼? – Joseph