Read File Synchronously and Asynchronously (Blocking and Non-blocking ways)

In this post we will learn to read a text file synchronously with a blocking code and asynchronously by writing non-blocking code. Node.js provides methods to read a file both synchronously and asynchronously in it’s ‘fs’ module. Synchronously reading a file using blocking methods of Node.js: Asynchronously reading a file using non-blocking methods of Node.js:

Simple Web Server Program in Node.js

Here we write a simple web server program in Node.js that serves static text to the client’s HTTP requests. The createServer method returns a http.Server object We are passing requestListener callback function as a parameter to createServer which automatically added to the ‘request’ event http.Server emits ‘request’ event when it receives a request The request … Read more

Piping Readable Stream to Writable Stream

In this post you’ll learn how to pipe readable stream into writable stream. Piping readable stream to standard output Line 1: Importing ‘request’ module which simplifies reading from http request. Make sure to download this module using npm install request Line 2: Requesting response from a web address Line 3: Piping the readable stream to … Read more

Print Prime Numbers in Java

In this post we will see couple of examples on how to print prime numbers in Java. A positive integer is called Prime Number when it is greater than 1 and divisible only with itself and by 1. Example: 2, 3, 5, 7, 11, 13, 17, 19 etc., Print Prime Numbers using custom square root … Read more

Finding Square Root of a Number in Java

In this post we will see an example on finding the Square Root of a Number. Square Root of a given number n is y, such that square of y is n. Below is the program to print square root of a given number. Program: Output: