Now I'm learning Node.js and Express and want to use the mysql module to render several unique pages, so instead of writing the line var connection=mysql.createConnection({user:'root', password: 'root'...etc}) for each file located in the routes directory, I am sure that it is best to just call my own mysql configuration file in each routing file.
However, where should I put the configuration file in the Express hierarchy and how can I call the file from each routing file? I know that all images, stylesheets and javascript files should be located in each specific directory in the public directory, but I do not know where to put all the other files that need to be accessed from the routing files.
I also want to know if all my files, from the main app.js to the files in the routes directory to the files in the public directory, etc ..., will be after I publish this web application on the Internet. If so, then I think I should not put the database configuration file in directories that clients can access ... right? In other words, I want to make sure which files clients can access and which not to avoid security attacks.
source share