Update index.js

Res undefined fix
Merge pull request #1 from petrbrzek/master

Fix: Added check if res obj exists