const express = require('express'); const app = express(); app.put('/users/:id', function (req, res) { const id = req.params.id; // extract data from the request body and update the user in the database res.send({ message: `User ${id} updated successfully` }); }); app.listen(3000, function () { console.log('Server started on port 3000'); });
const axios = require('axios'); const resourceId = '12345'; const resourceData = { name: 'New Resource Name', description: 'New Resource Description' }; axios.put(`/resources/${resourceId}`, resourceData) .then((response) => { console.log('Resource updated successfully'); }) .catch((error) => { console.log('Error updating resource:', error); });In this example, the put() method of the Axios library is used to send a PUT request to the /resources/:id endpoint with the updated resource data in the request body. The response from the server is logged to the console. Both of these examples use popular Node.js libraries and illustrate how the Node Put operation can be used to update resources on a server or in a database.