Book Image

Web Developer's Reference Guide

By : Joshua Johanan, Talha Khan, Ricardo Zea
Book Image

Web Developer's Reference Guide

By: Joshua Johanan, Talha Khan, Ricardo Zea

Overview of this book

This comprehensive reference guide takes you through each topic in web development and highlights the most popular and important elements of each area. Starting with HTML, you will learn key elements and attributes and how they relate to each other. Next, you will explore CSS pseudo-classes and pseudo-elements, followed by CSS properties and functions. This will introduce you to many powerful and new selectors. You will then move on to JavaScript. This section will not just introduce functions, but will provide you with an entire reference for the language and paradigms. You will discover more about three of the most popular frameworks today—Bootstrap, which builds on CSS, jQuery which builds on JavaScript, and AngularJS, which also builds on JavaScript. Finally, you will take a walk-through Node.js, which is a server-side framework that allows you to write programs in JavaScript.
Table of Contents (22 chapters)
Web Developer's Reference Guide
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
9
JavaScript Expressions, Operators, Statements, and Arrays
Index

The net module


The net module in Node.js allows us to create network connections. The connections that are created will be streams that we can write to and read from. This section will focus on just network connections and not HTTP. Node.js has a full HTTP module, and we will cover that in the next section.

All the functions assume that the net module has been loaded like this:

var net = require('net');

createServer

This function will create a TCP server:

net.createServer([options], [listener]) 

Return value

This returns a net.Server object.

Description

This function allows us to listen for connections. The returned object will be a net.Server object, and the connection listener will be passed to a net.Socket object. We will cover both of these objects shortly.

Here is a simple example that shows us how to listen and write to a socket. Each connection will have to be manually closed:

var net = require('net');
var server = net.createServer(function (connection) {
    connection.write('You connected...