Update index.js

Check connection for undefined