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

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745178443a4615306.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信