How to fix this error: app crashed - waiting for file changes before starting?

As a beginner, I followed a webdevsimplified course. I can not fix this error -> [nodemon] app crashed - waiting for file changes before starting... I attach also a photo if it helps.
No description
40 Replies
Jochem
Jochem6mo ago
src as a variable is undefined usually that means you tried to use querySelector and it failed to find the element you're looking for though I suppose in this case with node, it's something different. Impossible to tell without more info though
INDavid04
INDavid04OP6mo ago
yeah it makes sense, but node_modules is installed with npm i express ejs express-ejs-layouts and I did't modified those files at all
Jochem
Jochem6mo ago
you might be missing a .env file in your project root then? Otherwise, no idea
INDavid04
INDavid04OP6mo ago
.env is in the project root with this line DATABASE_URL=mongodb://localhost/mybrary should i change what is after localhost/? also in the video tutorial he used .load(), specifying after to use .parse() instead
INDavid04
INDavid04OP6mo ago
here is where he used the function
No description
INDavid04
INDavid04OP6mo ago
I saw in comments to use .config() instead, but got another error
glutonium
glutonium6mo ago
where is src coming from? like where is it defined
INDavid04
INDavid04OP6mo ago
1 sec
INDavid04
INDavid04OP6mo ago
No description
INDavid04
INDavid04OP6mo ago
however, after repacing parse() with config(), i got this Error: Cannot find module 'mangoose'
glutonium
glutonium6mo ago
dud u install mongoose? run npm i mongoose if not what does the variabe src represent?
INDavid04
INDavid04OP6mo ago
No description
INDavid04
INDavid04OP6mo ago
I don't know, but I do not use the parse() function anymore
glutonium
glutonium6mo ago
can u show the code where u r requiring mongoose u dont know? wdym u dont know the function u r trying to run even takes as arguments
INDavid04
INDavid04OP6mo ago
I said I am new to this stuff
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}

const express = require('express')
const app = express()
const expressLayouts = require('express-ejs-layouts')

const indexRouter = require('./routes/index')

app.set('view engine', 'ejs')
app.set('views', __dirname + '/views')
app.set('layout', 'layouts/layout')
app.use(expressLayouts)
app.use(express.static('public'))

/// Right here
const mangoose = require('mangoose')
mangoose.connect(process.env.DATABASE_URL, {useNewUrlParser: true })
const db = mangoose.connection
db.on('error', error => console.error(error))
db.once('open', () => console.log('Connected to Mongoose'))

app.use('/', indexRouter)

app.listen(process.env.PORT || 3000)
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}

const express = require('express')
const app = express()
const expressLayouts = require('express-ejs-layouts')

const indexRouter = require('./routes/index')

app.set('view engine', 'ejs')
app.set('views', __dirname + '/views')
app.set('layout', 'layouts/layout')
app.use(expressLayouts)
app.use(express.static('public'))

/// Right here
const mangoose = require('mangoose')
mangoose.connect(process.env.DATABASE_URL, {useNewUrlParser: true })
const db = mangoose.connection
db.on('error', error => console.error(error))
db.once('open', () => console.log('Connected to Mongoose'))

app.use('/', indexRouter)

app.listen(process.env.PORT || 3000)
ἔρως
ἔρως6mo ago
cannot find module mangoose you installed mongoose
INDavid04
INDavid04OP6mo ago
no way
ἔρως
ἔρως6mo ago
way
INDavid04
INDavid04OP6mo ago
glutonium
glutonium6mo ago
i get that but u wont be able to debug if u dont know what your code does u should understand what the function expects
ἔρως
ἔρως6mo ago
this is correct
glutonium
glutonium6mo ago
if u blindly follow someones footstep u will lose yourself pretty easily
ἔρως
ἔρως6mo ago
lose not loose
INDavid04
INDavid04OP6mo ago
so true
glutonium
glutonium6mo ago
;-;
ἔρως
ἔρως6mo ago
loose is the oposite of tight, lose is the oposite of find
glutonium
glutonium6mo ago
i mix them up all the time 😭
INDavid04
INDavid04OP6mo ago
i tried to understand but is very different from what i did in highscool with c++
ἔρως
ἔρως6mo ago
it is, but it isnt as hard as you think its always overwhelming at first
INDavid04
INDavid04OP6mo ago
sure
ἔρως
ἔρως6mo ago
it gets a lot easier
INDavid04
INDavid04OP6mo ago
hmm should i show you that?
INDavid04
INDavid04OP6mo ago
No description
ἔρως
ἔρως6mo ago
its mongoose not mangoose
INDavid04
INDavid04OP6mo ago
lol
ἔρως
ἔρως6mo ago
mongoose for mongodb, right?
INDavid04
INDavid04OP6mo ago
oh yeah in my native language 'o' is heard like 'a'
ἔρως
ἔρως6mo ago
mangoose sounds like a shitty superhero with awful super powers languages are fun
INDavid04
INDavid04OP6mo ago
thanks a lot guys, now it is works
ἔρως
ἔρως6mo ago
you're welcome

Did you find this page helpful?