Update server.js

added error checking