expressjsHow can I send an empty body using Express.js?
To send an empty body using Express.js, you can use the send() method. This method allows you to send an empty body response to the client. Here is an example of how to use it:
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send();
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
This will send an empty body response to the client.
The code above consists of the following parts:
const express = require('express');- This line imports the Express.js module.const app = express();- This line creates an Express.js application.app.get('/', (req, res) => {- This line creates a route handler for a GET request to the root path.res.send();- This line sends an empty body response to the client.app.listen(3000, () => {- This line starts the server on port 3000.
For more information, refer to the Express.js Documentation.
More of Expressjs
- How do I use Express.js to parse YAML files?
- How can I set up X-Frame-Options in ExpressJS?
- How do I use Zod with Express.js?
- How do I use Yarn to add Express.js to my project?
- How can I use the x-forwarded-for header in Express.js?
- How do I find Express.js tutorials on YouTube?
- How do I set up a YAML configuration file for a Node.js Express application?
- How can I use Node.js and Express together to create a web application?
- How do I use Express.js and Yarn together in a software development project?
- How can I disable the X-Powered-By header in Express.js?
See more codes...