Prabhu Kiran
Prabhu Kiran

Reputation: 1

ReferenceError: Mongoose is not defined - Node.js

I am a student and as part of the assignment, I am developing an weather app that connects to openweatherapp website and retrieves the data. When executing this from command prompt as nodemon index.js, I am getting the following error.

ReferenceError: mongoose is not defined at Object. (C:\Users\anand\Desktop\Sem 4\web apps\Assignment 3\2298917_193294482_708854\708854\app\index.js:7:18)

The code for index.js is

var http = require('http');
var express = require('express')
var app = express();
app.set('view engine', 'ejs');
var city = 'Las Vegas';
mongoose.connect('mongodb://prettyprinted:[email protected]: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);

Please advise.

Upvotes: 0

Views: 2218

Answers (1)

Valentin Bouis
Valentin Bouis

Reputation: 51

Yes you need to add the instruction

var mongoose = require('mongoose')

and be sure to do npm install mongoose

Upvotes: 2

Related Questions