question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

res.end is not a function

See original GitHub issue

Bug report

res.end is not a function

Describe the bug

When crating api using API routes, I am getting res.end is not a function. I created api folder under pages and start.js file inside api folder. export default function handle(req, res) { console.log(req.body) // The request body console.log(req.query) // The url querystring console.log(req.cookies) // The passed cookies res.end('Hello World') } A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to ‘https://codesandbox.io/embed/hello-world-mi42m
  2. Click on ‘…’
  3. Scroll down to ‘…’
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of Next.js: [e.g. 9.0.2]

Additional context

Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Vav4ikcommented, Sep 17, 2020

I had this error when accidentally swapped “request” and “result” sequence in callback function. Please make sure that you have (req, res) instead of (res, req).

0reactions
balazsorban44commented, Jan 29, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nodejs Promise "res.end is not a function" error - Stack Overflow
My code receives list of IDs and processes them making few database calls, that is why I had this "callback hell". Everything worked...
Read more >
Express.js res.end() Function - GeeksforGeeks
The res.end() function is used to end the response process. This method actually comes from the Node core, specifically the response.end() ...
Read more >
Express.js – res.end() Method - Tutorialspoint
The res.end() method ends the current response process. This method is used to quickly end the response without any data.
Read more >
[Solved]-Nodejs Promise "res.end is not a function" error-node.js
You've redefined res with this: processVMDelete(returnedVMIDs) .then(res => {...}) This will hide the higher scoped res associated with the overall request ...
Read more >
API Reference - Express 4.x
If not a function, type option is passed directly to the type-is library and this ... verify, This option, if supplied, is called...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found