【发布时间】:2019-12-15 23:51:43
【问题描述】:
文件没有在nodejs中上传它显示错误是: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 正在等待一些文件更改以重新启动它。因此,您在此处显示的代码有问题。
-
你能看看有什么问题的代码
-
实际上是我自己写的,我两天前才开始(nodejs)所以我找不到任何解决方案来修复它
-
如果有任何错误,你可以告诉我你是否有经验
标签: node.js node-modules nodemon