Sails.js -- Accessing local.js environment settings in controllers

In production I have AWS credentials stored as heroku config variables.

In development I want to include the config details in config/local.js, but how do I access the config details in a controller?

local.js contains:

module.exports = { aws_key: "...", aws_secret: "..." }

In my controller I have tried aws_key , config.aws_key , and others - but no luck. Is there a main app namespace that I can use to scope into the properties exported by local.js?

I am new to sails and I feel like this should be straight forward - any help would be appreciated.

Problem courtesy of: Drew Samsen


Solution found. Step 3 was where I was having trouble.


What I didn't realizewas that the module.exports.thing makes the thing object available through sails.config.thing . Good to know.

1)I created a new file at config/aws.js with the contents

// Get heroku config values = {
  key: process.env.AWS_KEY,
  secret: process.env.AWS_SECRET

2)In local.js put the actual AWS creds (this won't end up in the repository since sails automatically ignores local.js using gitignore).

aws: {
  key: actual-key,
  secret: actual-secret

This allows for local testing where we don't have access to the heroku config settings, while protecting these values from being exposed in a github repo.

3)Now, to access in the controller:

var aws_config =;

  accessKeyId: aws_config.key,
  secretAccessKey: aws_config.secret

Solution courtesy of: Drew Samsen


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow .