Book Image

The Node Craftsman Book

By : Manuel Kiessling
Book Image

The Node Craftsman Book

By: Manuel Kiessling

Overview of this book

The Node Craftsman Book helps JavaScript programmers with basic Node.js knowledge to now thoroughly master Node.js and JavaScript. This book dives you deeper into the craft of software development with Node.js and JavaScript, incuding object-orientation, test-driven development, database handling, web frameworks, and much more. The Node Craftsman Book shows you how to work with Node.js and how to think deeply about how you build your Node projects. You'll master how to build a complete Node.js application across six crafting milestones, and you'll learn many specific skills to achieve that mastery. These skills include how to work with the Node Package Manager in depth, how to connect your Node applications to databases, and how to write unit tests and end-to-end tests for your code. You'll experience the full Node.js development picture, and learn how to craft and control your Node.js applications - right through to fully-fledged web applications using REST, and integration with Angular applications.
Table of Contents (17 chapters)
Free Chapter
1
Part 1: Node.js Basics in Detail
2
Working with NPM and Packages
3
Test-driven Node.js Development
11
Milestone 1 – A First Passing Test Against the Server
13
Milestone 3 – Setting the Stage for a Continuous Delivery Workflow

Making the backend recognize different environments

But we are not yet done and need to refrain from opening our app just yet.

What's the problem?

Until now, we only used the database when running the specs. Now we have another client for the web service (and the underlying database), and this is the frontend application. We probably don't want our specs to wipe out the data we add through the application. We can circumvent this problem by using the different environments we created for db-migrate. Each environment has its own database setup, and this way we can keep things neatly separated – our specs work with one database setup, and the application with another one.

We need to add a helper script that detects the current environment when executing our code. Place this into src/backend/env.js:

'use strict';
(function() {
  var env;

  if (process.env.KW_ENV) {
    env = process.env.KW_ENV...