0

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.

1
  • 3
    var mongoose = require('mongoose'). That's just not there. Commented Jun 7, 2018 at 5:43

1 Answer 1

2

Yes you need to add the instruction

var mongoose = require('mongoose')

and be sure to do npm install mongoose

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.