使用yeoman angular-fullstack构建站点在本地效果很好,但是当我部署并使用dist / release版本时,这在服务器上给了我这个有趣的错误。
Error: Router.use() requires callback functions but got a [object Object]
at Function.proto.use (/home/bitnami/htdocs/dist/node_modules/express/lib/router/index.js:327:11)
at Object.<anonymous> (/home/bitnami/htdocs/dist/server/api/save/index.js:10:8)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.<anonymous> (/opt/bitnami/nodejs/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at module.exports (/home/bitnami/htdocs/dist/server/routes.js:13:25)
它似乎在这条线上失败了
router.use(multer({ dest: './public/uploads/'}));
虽然它在本地完全可以正常工作?我有点难过吗
想知道它是否与multer相关?我已经安装了节点模块。
有什么想法吗?
最佳答案
最新版本的multer
更改了API。如果查看examples,您将看到现在必须执行以下操作:
var upload = multer({ dest: './public/uploads/'});
// ...
router.use(upload.single('foofield'));
或
upload.array()
或upload.fields()
。关于javascript - multer可能出现问题?错误:Router.use()需要回调,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31613817/