Thursday 21 January 2016

Where to place database config/functions in Express?

Hello! I'm pretty new to Node.js and I've started developing a webapp in the Express framework which includes a classic user-login. I want to grab the details through a POST request, and use "router.post()" to validate the user with my database.However, I am a bit unsure of what the conventions are, regarding database-related files. I've made a new file called 'database.js' which has the connection info, and a function called validateUser(), which accepts two parameters - the username and login. I've exported the function to my router.js. In the function's callback, i want to do a "response.send()". But how can I do that when the 'response' is in my router.js? Maybe add 'response' as a parameter in the function.Anyways, do you guys have your database config, functions & router (with GET/POST handlers) all in the same file? Or do you seperate them? Hope I made sense.. :)

Submitted January 21, 2016 at 04:33PM by Piotyras

No comments:

Post a Comment