Buffer safety

The Buffer constructor is highly powerful, but with potential for danger.

Let's simply create an index.js file with the following code:

const http = require('http')const server = http.createServer((req, res) => {  if (req.method === 'GET') {    res.setHeader('Content-Type', 'text/html')    if (req.url === '/') return res.end(html())    res.setHeader('Content-Type', 'application/json')    if (req.url === '/friends') return res.end(friends())    return  }  if (req.method === 'POST') {    if (req.url === '/') return action(req, res)   }})function html (res) {  return `    <div id=friends></div>    <form>      <input id=friend> <input type=submit value="Add Friend">    </form>    <script>      void function () {        var friend = document.getElementById('friend') var friends = ...

Get Node Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.