nodemon - app crashed - waiting for file changes before starting
Asked Answered
I

9

8

I just started learning Node.js. The idea of this small application is to use express and mongosse to store some users in a based cloud database (mongoDB via mlab).

I have two seperate files :

User.js (models/User.js)

var mongoose = require('mongoose');

module.exports = mongoose.model('User', {

   email : string ,
   pwd : string

});

server.js (dossier root)

var express = require('express')
var cors = require('cors')
var bparser = require('body-parser')
var mongoose = require('mongoose')

var User = require('./models/User.js')

var app = express()

app.use(cors())
app.use(bparser.json())

app.post('/register', (req,res) => {
    userData = req.body;
    var user = new User(userData);

    user.save((err, result) => {
        if(err) console.log('IL YA UNE ERREUR')
        result.sendStatus(200);
    })

})

mongoose.connect('mongodb://user:[email protected]:61755/myapp', { useMongoClient: true } , (erreur) => {
    if(!erreur) 
    console.log('Connexion etablie');
})


app.listen(3000)

When I execute : nodemon server.js, I get the error below:

D:\Bureau\MEAN\appBackend\models\User.js:5
   email : string ,
           ^

ReferenceError: string is not defined
    at Object.<anonymous> (D:\Bureau\MEAN\appBackend\models\User.js:5:12)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\Bureau\MEAN\appBackend\server.js:6:12)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
[nodemon] app crashed - waiting for file changes before starting...

Do you have any idea about this error?

Ire answered 15/11, 2017 at 17:2 Comment(2)
just change your email : string , to email : 'string' same for pwdDymoke
@FabioAntunes email is a string (I mean the type for this variable is string), why do I have to make it that way?Ire
C
4

Mongoose expects you to specify types using the built-in constructor functions, which are named with capital letters, e.g. String, Number, Boolean, etc.

var mongoose = require('mongoose');

module.exports = mongoose.model('User', {

   email : String ,
   pwd : String

});
Concinnity answered 15/11, 2017 at 17:16 Comment(0)
E
1

define

module.exports = mongoose.model('User', new mongoose.Schema({ 

   email : 'string' ,
   pwd : 'string'
   })
});

There is no string variable in the code .

Encephalograph answered 15/11, 2017 at 17:9 Comment(0)
A
1

this message will be appeared always when there's any small mistake. I also faced this when module.exports type as module.export,just missed 's' only.

Adeliaadelice answered 11/10, 2018 at 19:17 Comment(0)
P
0

I come across with such error and on my case it was syntax error in the node js file.check your code for error as nodemon listen to change and run if no error there. This was the error that make app-crashed ....

console.log("this is author",cope["author"];

SyntaxError: missing ) after argument list at new Script (vm.js:79:7) at createScript (vm.js:251:10) at Object.runInThisContext (vm.js:303:10) at Module._compile (internal/modules/cjs/loader.js:657:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Function.Module.runMain (internal/modules/cjs/loader.js:742:12) at startup (internal/bootstrap/node.js:283:19) After i correct the error [nodemon] restarting due to changes... [nodemon] starting node server.js

That is it. Check for error in your code the nodemon automatically start the server.That is why nodemon is best rather than using node filename.js cz every time you have to start whenever you change the code.

Pretorius answered 27/2, 2019 at 10:35 Comment(0)
C
0

The common reason is that you're trying to access the database from an IP that isn't whitelisted. For my case, I was working on the same project on another PC. So, i had to whitelist the PC IP. To do this, login to your cloud base mongodb, navigate to that your particular db project, and click on network access, add IP address and click on current ip address. Also, make sure on your terminal, you run mongod to start your mongodb. That solve for me

Charlena answered 29/6, 2020 at 23:44 Comment(0)
I
0

Probably there is an instance already running. Run this(if you're using mac or linux-ubuntu)

killall node

and then try to run again.

Iphagenia answered 10/1 at 21:3 Comment(0)
M
-2

[nodemon] app crashed - waiting for file changes before starting...


You can fix this error with adding "start": "nodemon server.js" entry to your package.json file.

Menderes answered 17/11, 2018 at 8:4 Comment(1)
this type of error occurred when coder does mistake in alphabets...because nodejs is case sensitive...first check your code and correct spelling then nodemon will run correctly.Menderes
P
-2

Test with this command:

npm install --save express-load
Promotion answered 9/3, 2019 at 21:23 Comment(1)
Welcome to Stackoverflow! It would be great if you could add an explanation for why the OP should try this and how it is going to help them resolve their issue, thanks!Blakley
Z
-2

Many times we closed the PC and left the project running, when we used it again and ran the project again, that error appeared. I always solved it, restarting the pc. Everything worked perfectly.

Zara answered 21/6, 2019 at 21:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.