Latest Post

async/await has been the most promising feature of ES2017. It allows you to write asynchronous code in more elegant way saving you from the hassles of callback. async/await is supported from Node versions >= 8.5. However if you are writing JavaScript code targeting Node versions < 8.5, you need to set up a transpiler like Babel to convert your code compatible to your version of Node. To debug in this scenario, you need to make sure that Source Maps are generated and are linked in transpiled version generated by Babel. To do so, add following parameters in your .babelrc file:

1
2
"sourceMaps": true,
"retainLines": true
Continue Reading »

Recent Posts

In this blog post, I’ll show you how to create a fast text suggester using Koa2 framework of Node.js backed by Elasticsearch. Koa2 is a minimalist framework developed by team behind Express.js and comes with no middlewares inbuilt. Elasticsearch is a distributed search engine which comes with handy features for doing full text search.

To start with, I’ll use the koa-api-generator to bootstrap the application. Start by issuing following commands

1
2
3
npm i -g koa-api-generator
koa-api node-search-engine && cd node-search-engine
npm install
Continue Reading »

I had a requirement where I needed to do exact match search in ElasticSearch. After searching a bit I landed to this page of ElasticSearch documentation. I was thrilled that I got the solution quickly (thanking god and ElasticSearch team in my mind). Hence I started testing by creating an index using request below:

1
2
3
4
5
6
7
8
9
10
11
12
13
PUT localhost:9200/products/
{
  "mappings": {
    "product": {
      "properties": {
        "productName": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}
Continue Reading »

Recently we migrated one of our applications from MongoDB to PostgreSQL (which is a story for another time) at work. Similar to the script I developed for MongoDB in my last blog post, I developed one for PostgreSQL. pg_dump utility of PostgreSQL provides some nifty options to create different formats to create backup files. My script produces two types of backup files:

  • Plain bakup - This produces a gzipepd version of SQL script file which you can execute to restore the database.
  • Custom backup - This produces a compressed custom-format archive suitable for input into pg_restore.
Continue Reading »