Почему mongoose падает на сайт expressjs?Expressjs + Mongoose - Этот сайт недоступен?
Ниже мой код:
var express = require('express');
var mongoose = require('mongoose');
var app = express();
// Connect to mongodb
mongoose.connect("mongodb://localhost/testdb", function(err) {
if (err) throw err;
console.log("Successfully connected to mongodb");
// Start the application after the database connection is ready
app.listen(3000);
console.log("Listening on port 3000");
});
// With Mongoose, everything is derived from a Schema. Let's get a reference to it and define our users.
var userSchema = mongoose.Schema({
name: String,
username: { type: String, required: true, unique: true },
password: { type: String, required: true },
admin: Boolean,
location: String,
meta: {
age: Number,
website: String
},
created_at: Date,
updated_at: Date
});
// The next step is compiling our schema into a Model.
var User = mongoose.model('User', userSchema);
// Set route.
app.get("/", function(req, res) {
// We can access all of the user documents through our User model.
User.find(function (err, users) {
if (err) return console.error(err);
console.log(users);
})
});
Я получаю это в браузере:
This webpage is not available
Но в моем терминале я получаю результат:
Successfully connected to mongodb
Listening on port 3000
[ { _id: 57682f69feaf405c51fdf144,
username: 'testuser1',
email: '[email protected]' },
{ _id: 57683009feaf405c51fdf145,
username: 'testuser2',
email: '[email protected]' },
{ _id: 57683009feaf405c51fdf146,
username: 'testuser3',
email: '[email protected]' }]
Любые идеи, что у меня есть пропущенный?
Aww. Я вижу! Спасибо за помощь! – laukok
Рад, что я могу помочь! :) –
При возникновении ошибки следует также отправить ответ. – robertklep