Python3 with MySQL database

If you don't already have MySQL installed, install it with the following commands (mac only):

$ brew info mysql
$ brew install mysql
$ brew tap homebrew/services

Run the following commands to start or stop mysql. Start MySQL before proceeding:

$ brew services stop mysql
$ brew services start mysql

To see available sevices:

$ brew services list

To check MySQL version:

$ mysql -V

Set root password

Python3 with Oracle database


These instructions are for Mac OS:

First install homebrew. Never use sudo for brew.

$ /usr/bin/ruby -e "$(curl -fsSL"
$ which brew

Install Python3. The installation comes with pip3.

$ brew install python3
$ which pip3

Install cx_Oracle, the library that allows python3 to communicate with Oracle database.

File Management

Node uses the fs library to provide rich and powerful file management functionality. First let's a directory and some files:

$ mkdir data; cd data
$ touch provinces.txt capitals.txt

Add the following text to provinces.txt

British Columbia
New Brunswick
Newfoundland and Labrador
Nova Scotia
Prince Edward Island

Add the following to capitals.txt

Child Process

The child_process module allows you to communicate with other applications on your system by executing external processes in your environment. There are four kinds of child processes; exec(), spawn(), execFile(), fork(). I will be covering exec() and spawn() here. If a child process will execute once, use exec() function. For example the "cal" command on terminal prints the current month's calendar in the terminal. The command is executed once, prints a result and that's it. If a child process would be running for a long time and printing output several times, use spawn() function.


Node.js is an event-driven system. When you are performing different tasks, different events are emitted. You need to understand those events and how to use them. Events are defined by different modules. For example process.on() is an event. You can also create and use your own events. See example:

var events = require('events');
var eventEmitter = new events.EventEmitter();

eventEmitter.on('bankrupt', function() {
    console.log('You are bankrupt');

var networth = -20000;
if (networth < 0) {


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');

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


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


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 Following is a simple example, I picked up from Readline documentation.