nodemon 应用程序崩溃 - 在启动之前等待文件更改... nodejs [英] nodemon app crashed - waiting for file changes before starting... nodejs

查看:54
本文介绍了nodemon 应用程序崩溃 - 在启动之前等待文件更改... nodejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件未在 nodejs 中上传它显示错误,即:nodemon 应用程序崩溃 - 在启动之前等待文件更改... nodejs

file is not uploading in nodejs it shows error which is: nodemon app crashed - waiting for file changes before starting... nodejs

代码:

  var path = require('path');
  var express = require('express');
  var multer = require('multer');

  var app = express();
  var Storage = multer.diskStorage({
destination: './public/uploads/',
filename: (req, file, cb) => {
    cb(null, file.fieldname+"-"+Date.now()+path.extname(file.orignalname));
}
  })
  var upload = multer({
storage: Storage
  }).single('file');
  app.use(express.static(__dirname+"/public"));

  app.post('/uploadFile', upload , (req, res, next) => {
      res.send("Uploaded File: "+ req.file.filename);
  })
  app.listen(3000, () => console.log("Server Running at http://localhost:3000/"))

错误:

  TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
at validateString (internal/validators.js:125:11)
at Object.extname (path.js:830:5)
at DiskStorage.filename [as getFilename] (D:\nodejs\index.js:9:47)
at D:\nodejs\node_modules\multer\storage\disk.js:34:10
at DiskStorage.getDestination (D:\nodejs\node_modules\multer\storage\disk.js:22:51)
at DiskStorage._handleFile (D:\nodejs\node_modules\multer\storage\disk.js:31:8)
at D:\nodejs\node_modules\multer\lib\make-middleware.js:144:17
at allowAll (D:\nodejs\node_modules\multer\index.js:8:3)
at wrappedFileFilter (D:\nodejs\node_modules\multer\index.js:44:7)
at Busboy.<anonymous> (D:\nodejs\node_modules\multer\lib\make-middleware.js:114:7)
  [nodemon] app crashed - waiting for file changes before starting...

推荐答案

当 nodemon 因此错误而崩溃时,这意味着您的代码存在问题,导致其无法启动.

When nodemon crashes with this error, it means there is a problem with your code which prevents it from starting.

错误信息的第一行是实际错误:

The first line of the error message is the actual error:

TypeError [ERR_INVALID_ARG_TYPE]:路径"参数必须是字符串类型.接收类型未定义

您一定是将 undefined 而不是字符串传递给了函数,我猜在这一行:

You must have passed undefined instead of a string to a function, I would guess on this line:

cb(null, file.fieldname+"-"+Date.now()+path.extname(file.orignalname));

大概在file.originalname部分,你应该检查它是否定义

Probably in the file.originalname part, you should check if it is defined

这篇关于nodemon 应用程序崩溃 - 在启动之前等待文件更改... nodejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆