Refactored server side code

Refactored server side code. Put all database logic into dbconfig.js