Package Exports
- now-flow
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (now-flow) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
NowFlow - Automate your Zeit Now Deployments ·

NowFlow reduces the issues that arise when deploying to multiple environments (e.g. dev, staging, production, ...) using Zeit now-CLI. Simply define your alias and all your environment variables specific to each environment inside your traditional now.json, and let NowFlow do the rest.
Zeit now-CLI allows to deploy serverless applications to its own serverless infrastructure or to the most popular FaaS (i.e. Function as a Service) solutions (e.g. Google Cloud Functions, AWS Lambdas). However, a common challenge is to establish a sound strategy to manage multiple environments (e.g. dev, staging, production, ...). This process is obviously proned to errors. It is also tedious if you're deploying often. This is why we created now-flow.
Table of Contents
Install
Prerequisite
Zeit now-CLI must have been installed globally:
npm install now -gInstall NowFlow
Either install it globally:
npm install now-flow -gOr embed it inside your project to run it through npm:
npm install now-flow --save-devThe reason you would do that is to simply embed it in your project and that add a script in your package.json similar to "deploy:prod": "nowflow production". That way your collaborators don't have to worry to install globally yet another tool and can simply run npm run deploy:prod.
Problem Explained
Zeit now-CLI allows to deploy serverless applications to its own serverless infrastructure or to the most popular FaaS (i.e. Function as a Service) solutions (e.g. Google Cloud Functions, AWS Lambdas). However, a common challenge is to establish a sound strategy to manage multiple environments (e.g. dev, staging, production, ...). Typically, those environments might have a different:
hostingType(e.g. localhost, now, gcp, aws, ...).aliasif the application is deployed to Zeit now-CLI.startscript in the package.json.- Many other environment specific variables.
The manual solution is to:
- Update the
startscript in the package.json specific to your environment if you deploy to Zeit Now (e.g. production:"start": "NODE_ENV=production node index.js", staging:"start": "NODE_ENV=staging node index.js", localhost:"start": "node-dev index.js"). - If you're deploying to Google Cloud Functions, you might need to configure the
gcpproperty in the now.json. - If you're using the Webfunc serverless web framework, then you also need to set up the
env.activeproperty to the target environment in the now.json. - Run the right command (e.g.
nowif deploying to Zeit Now, andnow gcpif deploying to Google Cloud Functions). - Potentially alias your deployment if your're deploying to Zeit Now:
- Update the
aliasproperty of the now.json file to the alias name specific to your environment. - Run
now alias
- Update the
This process is obviously proned to errors. It is also tedious if you're deploying often. This is why we created now-flow.
Solution
How NowFlow Works?
Configure your now.json once, and then replace all the manual steps above with a single command similar to nowflow production.
Example:
now.json
{
"env": {
"active": "default",
"default": {
"hostingType": "localhost"
},
"staging": {
"hostingType": "gcp",
"gcp": {
"functionName": "yourapp-test",
"memory": 128
}
},
"production": {
"hostingType": "now",
"scripts": {
"start": "NODE_ENV=production node index.js"
},
"alias": "yourapp-prod"
}
}
}To deploy the production environment, simply run:
nowflow production This will deploy to Zeit Now and make sure that:
- The package.json that is being deployed will contain the start script
"NODE_ENV=production node index.js". - The
env.activeproperty of the now.json is set toproduction. - Once the deployment to Zeit Now is finished, it is automatically aliased to
yourapp-prod.
On the contrary, to deploy the staging environment, simply run:
nowflow staging This will deploy to Google Cloud Functions and make sure that:
- The
env.activeproperty of the now.json is set tostaging. - The now.json contains a
gcpproperty identical to the one defined in the staging configuration.
No more deployment then aliasing steps. No more worries that some environment variables have been properly deployed to the right environment.
Learn more details on how NowFlow works in the How Does NowFlow Work? under the FAQ section.
The Most Minimal Setup
You must first create a now.json file in the root of your project's directory as follow:
{
"env": {
"production": {
"alias": "yourapp-prod"
},
"test": {
"alias": "yourapp-test"
}
}
}Make sure there is at least one environment defined under the env property. Then simply run:
nowflow productionThe above will:
- Deploy your project to Zeit using the production config defined in the now.json.
- Will alias that deployment using the alias defined in the production config defined in the now.json (i.e. 'yourapp-prod').
Skipping Aliasing
If you haven't defined an alias property for a specific environment, then now aliasing will be perfomed after deployment to that environment if the hostingType was now. If on the other hand an alias was defined, but you wish to prevent any aliasing, use the following:
nowflow production --noaliasModifying The package.json's "scripts" property For Each Environment
As described in the intro, this is one of the key feature of now-flow. In the now.json, under each specific environment, you can add a "script" property that will completely override the one defined inside the package.json during the deployment. Once the deployment is completed, the package.json is restored to its original state.
now.json:
{
"env": {
"production": {
"scripts": {
"start": "NODE_ENV=production node index.js"
},
"alias": "yourapp-prod"
},
"test": {
"scripts": {
"start": "NODE_ENV=test node index.js"
},
"alias": "yourapp-test"
}
}
}nowflow production In the example above, we're making sure that the package.json contains a start script so that now can, for example, correctly start an express server.
If you're using the serverless web framework Webfunc, the above command will also make sure that the property env.active of the now.json is also set to production before deploying.
FAQ
How Does NowFlow Work?
NowFlow makes sure that both your package.json and your now.json are configured properly based on the environment you're targeting. It does that in 2 steps:
- Create a temporary backup of your files in case something goes wrong. That's why you should see that during your deployment, the following 2 files are created: .package.backup.json, .now.backup.json. Those files will automatically deleted if the deployment is successful.
- Modify both your package.json and your now.json based on the environment configuration contained in the now.json.
- Invoke the
nowcommand (ornow <hostingType>) to deploy. - If aliasing is required, then invoke
now alias. - If the deployment is successful, or if an error but is is successfully intercepted and displayed to the terminal, then:
- Restore both the package.json and your now.json to their original state.
- Delete the backup files created in step #1.
This Is What We re Up To
We are Neap, an Australian Technology consultancy powering the startup ecosystem in Sydney. We simply love building Tech and also meeting new people, so don't hesitate to connect with us at https://neap.co.
Our other open-sourced projects:
Web Framework & Deployment Tools
- webfunc: Write code for serverless similar to Express once, deploy everywhere.
- now-flow: Automate your Zeit Now Deployments.
GraphQL
- graphql-serverless: GraphQL (incl. a GraphiQL interface) middleware for webfunc.
- schemaglue: Naturally breaks down your monolithic graphql schema into bits and pieces and then glue them back together.
- graphql-s2s: Add GraphQL Schema support for type inheritance, generic typing, metadata decoration. Transpile the enriched GraphQL string schema into the standard string schema understood by graphql.js and the Apollo server client.
React & React Native
- react-native-game-engine: A lightweight game engine for react native.
- react-native-game-engine-handbook: A React Native app showcasing some examples using react-native-game-engine.
Tools
- aws-cloudwatch-logger: Promise based logger for AWS CloudWatch LogStream.
License
Copyright (c) 2018, Neap Pty Ltd. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Neap Pty Ltd nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NEAP PTY LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
