Node.js for PHP Developer

php

function roomlist() {
  $rooms = array();
  $room_list = mysql_query(
    'SELECT room FROM '.SQL_PREFIX.'chats GROUP BY room ORDER BY room ASC'
  );
  while (
    $row = mysql_fetch_assoc($room_list)) {
    $room = $row['room'];
    $rooms[] = $room;
  }
  print json_encode($r);
}

node.js

function roomlist() {
  const rooms = [];
  link.query(
    'SELECT room FROM ' + SQL_PREFIX + 'chats GROUP BY room ORDER BY room ASC',
    function (err, rows, fields) {
      for (var r = 0; r < rows.length; ++r) {
        const row = rows[r];
        const room = row['room'];
        rooms.push(room);
      }
      res.writeHead(200, {
        'Content-Type': 'text/plain'
      });
      res.end(JSON.stringify(r));
    }
  });
};

code from: Node.js for PHP developers, viii

Chapters

Chapter 1, Node.js Basics Chapter 2, A Simple Node.js Framework Chapter 3, Simple Callbacks Chapter 4, Advanced Callbacks

Chapter 5, HTTP Responses Chapter 6, Syntax Chapter 7, Variables Chapter 8, Classes Chapter 9, File Access Chapter 10, MySQL Access Chapter 11, Plain Text, JSON, and XML Chapter 12, Miscellaneous Functions

Node.js for Java Developer

What Else?
inflearn react api server -50% 할인쿠폰: 15108-f2af1e086101 buy me a coffee