ReferenceError:未定义Mongoose - Node.js

时间:2018-06-07 05:43:04

标签: node.js mongodb mongoose

我是学生,作为作业的一部分,我正在开发一个连接到openweatherapp website并检索数据的天气应用程序。当从命令提示符执行此命令作为nodemon index.js时,我收到以下错误。

  

ReferenceError:未定义mongoose       在对象。 (C:\ Users \ anand \ Desktop \ Sem 4 \ web apps \ Assignment 3 \ 2298917_193294482_708854 \ 708854 \ app \ index.js:7:18)

index.js的代码是

var http = require('http');
var express = require('express')
var app = express();
app.set('view engine', 'ejs');
var city = 'Las Vegas';
mongoose.connect('mongodb://prettyprinted:Password11@ds253879.mlab.com:53879/express_weather')

var citySchema = new mongoose.Schema({
    name: String
});


var request = require('request');
//http.createServer(function (request, response) {
    //var request = require('request');
var url = 'http://api.openweathermap.org/data/2.5/weather?q=London&appid=7970f50f59ddccaf607b8a4890574039';
app.get('/', function (req,res) {
    request(url, function (error, response, body) {
        weather_json = JSON.parse(body);
        console.log(weather_json);
        var weather = {
            city: city,
            //temperture: Math.round(weather_json.main.temp),
            Descrip: weather_json.weather[0].description,
            icon: weather_json.weather[0].icon
        };
        var weather_dat = {weather : weather};

        res.render('weather', weather_dat);
    });
    //res.render('index')
});
app.listen(11223);

请指教。

1 个答案:

答案 0 :(得分:1)

是的,您需要添加说明

var mongoose = require('mongoose')

并确保'npm install mongoose'