Book Image

Building Scalable Apps with Redis and Node.js

By : Joshua Johanan
Book Image

Building Scalable Apps with Redis and Node.js

By: Joshua Johanan

Overview of this book

Table of Contents (17 chapters)
Building Scalable Apps with Redis and Node.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Scripting our new tools


We have automated some tasks, but we have created an issue where we must run two to three commands to accomplish each task. We want to always shoot for one command. We will create a script to launch our development server and collect the static files. First, create a file named set_env.sh. This file will load our environment files so that we can then run our different commands. Paste this into it:

#!/bin/bash
if [ $# -ne 1 ]; then
  echo "Please pass in the environment as the first argument"
  exit 1
fi

source ./$1.env
source ./$1_secret.env

if [ $? != 0 ]; then
  echo "Create the needed environment files"
  exit $?
fi

This uses bash and if you have never scripted with bash before, it can look a little strange. The first if condition checks the number of passed-in arguments (?#) to see if it is not equal to 1. If that is true, exit and let the user know the environment should be passed in. The next step is to build the name of the environment files from the first...