Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

nodejs json data serving

// UPDATE
app.put('/users/:id', (req, res) => {
  readFile(data => {
    // add the new user
    const userId = req.params['id'];
    data[userId] = req.body;

    writeFile(JSON.stringify(data, null, 2), () => {
      res.status(200).send(`users id:${userId} updated`);
    });
  }, true);
});
Source by robkendal.co.uk #
 
PREVIOUS NEXT
Tagged: #nodejs #json #data #serving
ADD COMMENT
Topic
Name
6+2 =