Skip to content
Simple "node" configuration solution for Rails applications
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Simple "node" configuration solution for Rails applications.


"node" is a single machine, which your Rails application is running on. So "node" configuration is the configuration for that specific machine. For example:

  • Your development laptop is also a "node" and needs a local configuration for development.
  • Your server is also a "node", but it needs a different configuration for production.


We need to maintain lots of configuration keys specific for a "node", like AWS access keys, Google-Analytics keys and much more...


  • We want all of this keys to be defined in a single file
  • We want all of this keys to be loaded automatically on Rails startup
  • We want all of this keys to be available inside Rails application
  • We want that a missing key results in a descriptive error
  • We want this keys to be loaded into a process, which doesn't load the whole application

This is what NodeConfig tries to simplify.


# Gemfile
$ bundle install # Install the gem
$ rails generate node_config # Generate configuration files


Put your node configuration into generated RAILS_ROOT/config/node_config.yml.

Within a loaded Rails application

Your node configuration is available in Rails application config. This is done by the generated initializer config/initializers/node_config.rb.

# config/node_config.yml
  bar: :baz
# rails console #=> {"bar" => :baz} #=> :baz

In a Rake task:

# Rakefile
task :my_task do
  puts( #=> baz

Using without loading Rails

Outside the Rails you can access the node configuration through the top level module named as your Rails application: #=> :baz

This is done by loading the generated RAILS_ROOT/config/node_config.rb.

If you have a Rake task for which the node configuration should be available without loading whole Rails, use the generated shortcut task.

# lib/tasks/my_task_which_doesnt_need_rails.rake
task :my_task_which_doesnt_need_rails => :node_config do
  puts( #=> baz

Or as command line in your Procfile ( for a worker (

worker: bundle exec rake node_config resque:work

If you have a script for which the node configuration should be available without loading whole Rails, be aware that the process has to be bundled. Otherwise it may not find the gem.

For example in your backup script (

# config/backup.rb
require File.expand_path("../node_config", __FILE__) #=> :baz

Same when deploying with Capistrano (

# config/deploy.rb
require File.expand_path("../node_config", __FILE__) #=> :baz

Or even in an external Ruby script:

# foo.rb
require "/srv/www/pet_shop/current/config/node_config" #=> :baz

If you have a process, which isn't bundled, then require the gem manually:

# foo.rb
require "rubygems"
require "node_config"

require "/srv/www/pet_shop/current/config/node_config" #=> :baz


Under the hood NodeConfig uses HashWithStructAccess, so a missing key will result in appropriate NoMethodError (see for details).

Using with Git

Of course you have instruct Git to ignore config/node.yml.

But it's a good practice to maintain a configuration template with the list of required keys, for example in config/node.yml.template.

Something went wrong with that request. Please try again.