Built-in Modules

A module encapsulates relate code, such as code for handling files, into a single unit of code. Node ships with many useful modules. These are called built-in modules. Programmers can create new modules. These are called custom modules.

Following is a list of some built-in modules:

Create server

The following code creates a server and assign a port.

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Your node server is running');
}).listen(8282);

Simply run the code and open http://localhost:8282 in your browser.

Streams

We have already seen how to read stdin (input from the terminal) as follows:

console.log(process.stdin);

A program can take input from many different sources of streaming data. Readline module provides an interface to read data from any Readable stream including process.stdin. See https://nodejs.org/api/readline.html. Following is a simple example, I picked up from Readline documentation.

Process Object

The process object is available globally meaning that it can be accessed from anywhere in the code. It allows us to fetch information regarding the current process instance; information such as environmental variables, path, stdin, and stdout.

console.log(process.argv);

Save this code as processdemo.js. To run:

$ node processdemo.js

This code outputs the parameters used when the process starts. It's output is as follows:

Node Package Manager

Node Package Manager (npm) comes bundled with Node. It allows you do search Node repositories for packages and modules. Anything that is searchable on search.nodejs.org is also searchable by npm. npm can be used to install Node packages on your system. It also performs version and dependency management for all Node packages installing on your system. To find out the version of npm you are using, simply type the following command

$ npm --version
2.15.9

To upgrade you npm,

Node.js

Node is an open source runtime environment for server-side applications. It allows you to run JavaScript on the server in addition to the browser. Almost all of the new and most widely used JavaScript solutions use Node in one form or another.

Installing Node.js

Download from https://nodejs.org. Install with default options. To check, type the following on the terminal

What is Caching

A cache is a temporary data store that usually contains pre-computed data. The purpose of a cache is to provide the data the next time someone asks for it without having to re-compute the data. For example, your website needs to run a complex query to fetch results of a user request. A complex query takes time to run and uses the system's resources for the query to run. Every time someone click on a link, this query needs to run. However, if you cache the results, you can simple provide results from the cache rather than having to re-query the data.

Quick Introduction to Google Cloud

Google Cloud Platform (GCP) offers many services. They can loosely be classified as:

  • compute services
  • storage services
  • big data services
  • identity and security services
  • management tools
  • developer tools
  • other services

Compute services includes virtual machines, containers, and functions.

Storage services allow storage of files, archival storage, and persistence data. Data services include NoSQL, RDBMS, Hadoop and Spark.

Quick Introduction to Amazon Cloud

Amazon uses Amazon Elastic Cloud Compute (EC2) for provide cloud services. Following are some characteristics of EC2

Elastic IP

Servers are accessed through IP addresses. In the cloud, we spin up new virtual servers on the fly. To efficiently deal with these changes, elastic IPs are used. They are not dynamic addresses assigned to your account. Servers on the cloud are accessed through these elastic IP addresses.

Pages