I'm using the Node-Postgres package for querying a postgresql/postgis database for an app I'm building within the Sails.js framework.
I don't know where the best place to store my connection string for the node-postgres package would be to make it accessible in models and controllers but still secure.
For example, if I want to execute a query against the postgres database from within a model, what I currently do:
var conString = "postgres://postgres:mypass@localhost:5432/myapp_dev";
var client = new pg.Client(conString);
client.connect();
var junk = [];
client.query('SELECT * FROM junk', function (err, result) {
// Stuff I do with the query result
});
Obviously it's bad practice/inconvenient to declare this connectionstring and new client every time I need to execute a query. So, what I would like to be able to do is:
client.connect();
var junk = [];
client.query('SELECT * FROM junk', function (err, result) {
// Stuff I do with the query result
});
So I just removed the conString and new client declarations. But I don't know where in my app to store those to make them accessible yet secure.
My directory structure follows the standard Sails.js application structure, similar to this: http://runnable.com/UlbJJhdpQyoWAAAK/sails-js-example-project-for-node-js-and-webserver
Any help would be appreciated