How to implement simple Factory Pattern in Node.js

Instead of using class constructors or new keyword to create an object of a class, we can abstract this process. So, we can determine the type of object at run-time, by the time of generating that class object. The implementation seems like Factory Method, but simpler than Factory Method. This simple Factory is not treated as a standard GoF design pattern, but the approach is common to any place where we want to separate the code that varies a lot from the code that does not vary.

In this tutorial, grokonez shows you how to do it in NodeJs.

[Continue reading…] “How to implement simple Factory Pattern in Node.js”

How to implement Singleton in Node.js

Singleton is object that can have only a single, unique instance, with a single point of access. Node.js module system provides simple way to implement Singleton using module.exports. Module will be cached when it is accessed using require() statement. So our module is merely a cached instance although it behaves like a Singleton.

In this tutorial, we’re gonna look at ways to implement this kind of Singleton in Node.js:

  • Singleton Object
  • Singleton Class

[Continue reading…] “How to implement Singleton in Node.js”

Java Prototype Pattern tutorial with example

In many cases, creating a new instance is a costly operation. Fortunately, we can copy or clone an instance of an existing one instead of creating from scratch. This approach can be done by using Prototype Pattern, one of Creational Patterns.

[Continue reading…] “Java Prototype Pattern tutorial with example”

Java Date Time – How to build SpringBoot RestApi – Post/Get request with Java Date Time using Jackson and Make Query with Spring JPA example


In the tutorial, we build a SpringBoot RestAPIs example that post/get data with java.util.Date time and save it to MySQL/PostgreSQL database using Spring JPA. Working with Java Date Time is an exciting part but also not easy task, fortunately we have the supporting from utilities of Jackson lib, now the job can be done in an easy way.

Let’s do details by steps!

[Continue reading…] “Java Date Time – How to build SpringBoot RestApi – Post/Get request with Java Date Time using Jackson and Make Query with Spring JPA example”

How to Sort Java List Objects by Date property with Examples


In the tutorial, We discuss how to Sort Java List Objects by Date property with difference Date types: java.util.Date(using SimpleDateFormat), LocalDate, LocalDateTime. Java provides 2 main approaches for sorting Java List with Comparator:

  • java.util.Collections.sort(List list, Comparator< ? super Customer> c): sorting the specified list according to the order providing by the specified comparator.
  • java.util.Collection.stream().sorted(Comparator< ? super T> comparator): returning a stream consisting of the elements of this stream, sorted according to the provided Comparator.

Let’s do more details with Java syntax examples (Java 7 and Java 8) by descending and ascending sorting order.

[Continue reading…] “How to Sort Java List Objects by Date property with Examples”

How to Sort an Array in Java with Examples


In the tutorial, we will discuss how to Sort an Array with Java in ascending and descending order. java.util.Arrays class provides a lot of Methods to sort an Array with difference types:

  • With Primitives Array, We use the method such as: static void sort(int[] a).
  • With String or Objects Array that implement Comparable, We use method: static void sort(Object[] a).
  • With Custom Object Array that no implement Comparable, We use method: sort(T[] a, Comparator< ? super T> c).

Let’s do more details with Java Array Sorting.

[Continue reading…] “How to Sort an Array in Java with Examples”

Django – How to upload, view, delete file using ModelForm and MySQL

In this tutorial, we’re gonna look at way to upload file in Django using Django ModelForm and save its information to MySQL Database. We also have UI to view list of uploaded items and function to delete specific file.

Related Post: Simple way to upload file in Django

[Continue reading…] “Django – How to upload, view, delete file using ModelForm and MySQL”

Excel File/Data – Nodejs Express RestAPI – Download/Extract Excel(.xlsx) Data/File from MySQL

In the tutorial, Grokonez shows how to download & extract Excel(.xlsx) File/Data from MySQL with Nodejs Express and exceljs lib.

Related posts:
Node.js Extract MySQL Data to Excel(.xlsx) File – using exceljs

[Continue reading…] “Excel File/Data – Nodejs Express RestAPI – Download/Extract Excel(.xlsx) Data/File from MySQL”

CSV File/Data – Nodejs Express RestAPI – Download/Extract CSV Data/File from MySQL

In the tutorial, Grokonez shows how to download & extract CSV File/Data from MySQL with Nodejs Express and json2csv lib.

Related posts:
Node.js Extract MySQL Data to CSV File – using Json2Csv

[Continue reading…] “CSV File/Data – Nodejs Express RestAPI – Download/Extract CSV Data/File from MySQL”