How can you send JSON data as a response using the http module in Node.js?
- response.sendJSON(jsonDat
- response.write(JSON.stringify(jsonData))
- response.json(jsonData)
- response.send(jsonData)
To send JSON data as a response using the http module in Node.js, you should use response.write(JSON.stringify(jsonData)). This method writes the JSON data as a string to the response. The other options are not valid methods for sending JSON data in the http module.
Loading...
Related Quiz
- Which of the following is a suitable method to prevent variable leakage in the global scope?
- You are developing an Express.js application that needs to validate user input on a specific route. How would you implement middleware to efficiently validate input for that route?
- Which of the following is true about the prototype chain in JavaScript?
- When using stubs, the main focus is on ______ rather than on verifying interactions between objects.
- How can you prevent replay attacks when using OAuth 2.0?