I've recently started playing around with AngularJS and Node.js and I'm having a bit of trouble figuring out where exactly to place my node-mysql connection block. I have my app split up into HTML and JavaScript files for each separate page and each JavaScript file holds the config and controller blocks for the respective HTML page. If I want my app to connect to a MySQL database, where do I put the connection block? My initial thought was to put it in app.js, but then how would the other pages utilize that connection as well? Any help is greatly appreciated!
-
Welcome to StackOverflow and thanks for your question. Hope to see you around. You have some code to show us? This will help to provide an answer.Filipe Merker– Filipe Merker12/15/2015 00:02:08Commented Dec 15, 2015 at 0:02
-
Put it in a factory service. docs.angularjs.org/guide/servicesgeorgeawg– georgeawg12/15/2015 00:41:29Commented Dec 15, 2015 at 0:41
Add a comment
|
1 Answer
I assume you're using Node as your server in this case, you'll want your node-mysql information to be somewhere in your server code.
-
Do I use this server file as an export to be used in the other js files?Trey Blanden– Trey Blanden12/15/2015 18:00:42Commented Dec 15, 2015 at 18:00
-
It seems you are a bit confused as to the relationship between your client(Angular) code and your server(Node) code. I'd recommend taking a look at a quick example: scotch.io/tutorials/…brettkc– brettkc12/15/2015 18:03:53Commented Dec 15, 2015 at 18:03