node.js nodemon - 应用程序崩溃 - 在启动之前等待文件更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47313247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nodemon - app crashed - waiting for file changes before starting
提问by MDIT
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).
我刚开始学习 Node.js。这个小应用程序的想法是使用 express 和 mongosse 将一些用户存储在一个基于云的数据库(通过 mlab 的 mongoDB)中。
I have two seperate files :
我有两个单独的文件:
User.js (models/User.js)
User.js(模型/User.js)
var mongoose = require('mongoose');
module.exports = mongoose.model('User', {
email : string ,
pwd : string
});
server.js (dossier root)
server.js(档案根)
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:
当我执行 : 时nodemon server.js,出现以下错误:
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?
你对这个错误有什么想法吗?
采纳答案by Raphael Serota
Mongoose expects you to specify types using the built-in constructor functions, which are named with capital letters, e.g. String, Number, Boolean, etc.
猫鼬希望你使用内置的构造函数,它被命名以大写字母,如指定类型String,Number,Boolean,等。
var mongoose = require('mongoose');
module.exports = mongoose.model('User', {
email : String ,
pwd : String
});
回答by Sujeewa K. Abeysinghe
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.
出现任何小错误时都会出现此消息。当module.exports 类型为module.export 时,我也遇到了这个问题,只是错过了's'。
回答by Himanshu sharma
define
定义
module.exports = mongoose.model('User', new mongoose.Schema({
email : 'string' ,
pwd : 'string'
})
});
There is no string variable in the code .
代码中没有字符串变量。
回答by yosef girma
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 ....
我遇到了这样的错误,在我的情况下,它是节点 js 文件中的语法错误。检查你的代码是否有错误,因为 nodemon 监听更改并运行,如果那里没有错误。这是使应用程序崩溃的错误....
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
SyntaxError: missing ) 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) 在 Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) 在 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) 在启动时 (internal/bootstrap/node.js:283:19) 在我纠正错误后 [nodemon] 由于更改而重新启动... [nodemon] 正在启动
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.
这就对了。检查代码中的错误,nodemon 会自动启动服务器。这就是为什么 nodemon 最好而不是每次更改代码时都必须启动时使用 node filename.js cz。
回答by Sthefane Soares
Test with this command:
用这个命令测试:
npm install --save express-load
回答by Miguel Herrera
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.
很多时候我们关闭PC并让项目运行,当我们再次使用它并再次运行项目时,就会出现该错误。我总是解决它,重新启动电脑。一切都很完美。
回答by Adeel Farooq
[nodemon] app crashed - waiting for file changes before starting...
[nodemon] 应用程序崩溃 - 在开始之前等待文件更改...
You can fix this error with adding "start": "nodemon server.js"entry to your package.jsonfile.
您可以通过向文件中添加"start": "nodemon server.js"条目来修复此错误package.json。

