当前位置:   article > 正文

node.js写入文件踩坑_throw new err_invalid_callback(callback);

throw new err_invalid_callback(callback);
  1. function writeFile(){
  2. fs.writeFile("how.html","bye");
  3. return "write successful";
  4. }

报错如下:

  1. throw new ERR_INVALID_CALLBACK(callback);
  2. ^
  3. TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
  4. [90m at maybeCallback (node:fs:174:3)[39m
  5. [90m at Object.writeFile (node:fs:2091:14)[39m
  6. at Object.writeFile [as /writeFile] (C:\陆哥\project_nodejs\src\file\requestHandlers.js:10:5)
  7. at route (C:\陆哥\project_nodejs\src\router\router.js:3:26)
  8. at Server.onRequest (C:\陆哥\project_nodejs\src\router\server.js:7:12)
  9. [90m at Server.emit (node:events:394:28)[39m
  10. [90m at parserOnIncoming (node:_http_server:927:12)[39m
  11. [90m at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)[39m {
  12. code: [32m'ERR_INVALID_CALLBACK'[39m

查了一下发现原来是writeFile调用还需要第三个参数callback

修改如下

fu
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/198100?site
推荐阅读
相关标签
  

闽ICP备14008679号