Book Image

React Components

By : Christopher Pitt
Book Image

React Components

By: Christopher Pitt

Overview of this book

The reader will learn how to use React and its component-based architecture in order to develop modern user interfaces. A new holistic way of thinking about UI development will establish throughout this book and the reader will discover the power of React components with many examples. After reading the book and following the example application, the reader has built a small to a mid-size application with React using a component based UI architecture. The book will take the reader through a journey to discover the benefits of component-based user interfaces over the classical MVC architecture. Throughout the book, the reader will develop a wide range of components and then bring them together to build a component-based UI. By the end of this book, readers would have learned several techniques to build powerful components and how the component-based development is beneficial over regular web development.
Table of Contents (17 chapters)
React Components
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Creating a simple server


Now that we can render components to HTML strings, it would serve us better to have a way to respond to HTTP requests with HTML responses.

Fortunately, Node.js also includes a neat little HTTP server library. We can use the following code, in the server.js file, to respond to HTTP requests:

var http = require("http");

var server = http.createServer(
    function (request, response) {
        response.writeHead(200, {
            "Content-Type": "text/html"
        });

        response.end(
            require("./hello-world")
        );
    }
);

server.listen(3000, "127.0.0.1");

To use the HTTP server library, we need to require/import it. We create a new server, and in the callback parameter, respond to individual HTTP requests.

For each request, we set a content type and respond with the HTML value of our hello-world.js file. The server listens on port 3000, which means you'll need to open http://127.0.0.1:3000 to see this message.

Before we can do that, we also...