最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Equivalent of console.log to debug code in NextJS API routes? - Stack Overflow

programmeradmin1浏览0评论

I'm using nextjs API routes in my next app, and I have some code that runs when I send a POST request.

If the code that runs in the API route has errors or doesn't work right, I can't debug it because I can't use something like console.log to see what's happening because it won't log to the frontend page. Is there some alternative?

Maybe it would be in the network tab or involve throwing errors or sending something, I'm not sure.

I'm using nextjs API routes in my next app, and I have some code that runs when I send a POST request.

If the code that runs in the API route has errors or doesn't work right, I can't debug it because I can't use something like console.log to see what's happening because it won't log to the frontend page. Is there some alternative?

Maybe it would be in the network tab or involve throwing errors or sending something, I'm not sure.

Share Improve this question edited Dec 25, 2022 at 2:33 Nora Söderlund 1,2014 silver badges18 bronze badges asked Dec 25, 2022 at 0:11 Hudson EtkinHudson Etkin 2972 gold badges4 silver badges9 bronze badges 4
  • console.log will log in your terminal, just take a look there! – Evert Commented Dec 25, 2022 at 0:12
  • 7 I believe the OP is indicating that the standard console.log doesn't seem to work properly in the new App Router route.ts setup. Server standard out doesn't show anything at the terminal when invoking console.log in a POST method. I too am having this same problem. – bencodesall Commented Jul 12, 2023 at 21:20
  • @bencodesall did you find a solution to the problem? – Nikolai Commented Oct 1, 2023 at 0:20
  • No answer, but I believe there was some wonky IoC/DI that was obfuscating the logging. Switched to using a DI'd Logger and solved the immediate need. – bencodesall Commented Oct 10, 2023 at 18:10
Add a ment  | 

1 Answer 1

Reset to default 3

NextJS's server will log to the terminal that's running npm run dev this isn't within the browser.

Try look there and see if it shows.

发布评论

评论列表(0)

  1. 暂无评论