{"id":19410061,"url":"https://github.com/nicolasdao/now-flow","last_synced_at":"2025-04-24T10:32:19.138Z","repository":{"id":81202269,"uuid":"114758287","full_name":"nicolasdao/now-flow","owner":"nicolasdao","description":"Augment the now-CLI to support AWS Lambdas, GCP that can react to events other then HTTPS requests (Pub/Sub \u0026 Storage changes) and better deployment configurations when managing multiple environments (e.g. staging, UAT, production).","archived":false,"fork":false,"pushed_at":"2018-06-28T07:07:55.000Z","size":186,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-01T16:03:41.343Z","etag":null,"topics":["aws-lambda","deployment","faas","gcf","neap","now-cli","pubsub","serverless","zeit"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nicolasdao.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-19T11:40:21.000Z","updated_at":"2022-02-06T15:52:03.000Z","dependencies_parsed_at":"2023-07-11T14:35:21.033Z","dependency_job_id":null,"html_url":"https://github.com/nicolasdao/now-flow","commit_stats":{"total_commits":50,"total_committers":2,"mean_commits":25.0,"dds":"0.18000000000000005","last_synced_commit":"bdc9c4c7f646b99531993ce0e7b16559c1142259"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolasdao%2Fnow-flow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolasdao%2Fnow-flow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolasdao%2Fnow-flow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolasdao%2Fnow-flow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicolasdao","download_url":"https://codeload.github.com/nicolasdao/now-flow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223718739,"owners_count":17191505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","deployment","faas","gcf","neap","now-cli","pubsub","serverless","zeit"],"created_at":"2024-11-10T12:14:42.538Z","updated_at":"2024-11-10T12:14:43.007Z","avatar_url":"https://github.com/nicolasdao.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NowFlow - Automate your Zeit Now Deployments \u0026middot;  [![NPM](https://img.shields.io/npm/v/now-flow.svg?style=flat)](https://www.npmjs.com/package/now-flow) [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) [![Neap](https://neap.co/img/made_by_neap.svg)](#this-is-what-we-re-up-to)\nOut-of-the-box, [_Zeit now-CLI_](https://zeit.co/now) does not offer any opiniated way to organize your variables on a per environment basis (e.g. database credentials, keys, ...). As of version 9.2.5, bugs still exist to deploy to AWS lambdas, and no support is provided to make functions deployed to Google Cloud to react to other events than an HTTPS request (e.g. Google Cloud Functions can react to Pub/Sub topics (very usefull for event-driven architecture), Google Storage or Firebase database changes). __*NowFlow* enables all those features by simply configuring your traditional *now.json*.__ \n\nNowFlow offers a strategy to manage multiple environments for any type of nodejs projects. It works especially well when it is combined with [__*Webfunc*__](https://github.com/nicolasdao/webfunc). Together, those 2 projects allow to deploy Express-like apps to the most popular serverless platforms (Zeit Now, AWS Lambdas, GCF) and will unlock apps that can react to __*Google Pub/Sub Topics*__ and __*Google Storage changes*__ (more info in the [FAQ](#faq) / [What Problems Does NowFlow Solve](#what-problems-does-nowflow-solve)).\n\n# Table of Contents\n\u003e * [Install](#install)\n\u003e * [How To Use It?](#how-to-use-it)\n\u003e   - [Basics](#basics)\n\u003e   - [Deploying To Google Functions or AWS](#deploying-to-google-functions-or-aws)\n\u003e   - [Google Cloud Functions for Pub/Sub or Storage Events](#google-cloud-functions-for-pubsub-or-storage-events)\n\u003e   - [The Most Minimal Setup](#the-most-minimal-setup)\n\u003e   - [Skipping Aliasing](#skipping-aliasing)\n\u003e   - [Modifying The package.json's \"scripts\" property For Each Environment](#modifying-the-packagejsons-scripts-property-for-each-environment)\n\u003e * [FAQ](#faq)\n\u003e * [About Us](#this-is-what-we-re-up-to)\n\u003e * [License](#license)\n\n# Install\n## Prerequisite\n\u003e [Zeit now-CLI](https://github.com/zeit/now-cli) must have been installed globally. The lastest stable version of now that works is @9.0.0. We're currently working on fixing the issues with more recent versions of now.\n\n```\nnpm install now@9.0.0 -g\n```\n\n## Install NowFlow\nEmbed it inside your project as a dev dependency to run it through npm (RECOMMENDED WAY):\n```\nnpm install now-flow --save-dev\n```\n\nOr install it globally:\n```\nnpm install now-flow -g\n```\n# How To Use It?\n## Basics\nConfigure your _now.json_ once, and then replace all the manual steps above with a single command similar to `nowflow production` (or `npm run deploy:prod` if you've configured that task in your package.json, which is the recommended way).\n\n__*Example:*__\n\n_now.json_\n```js\n{\n  \"env\": {\n    \"active\": \"default\",\n    \"default\": {\n      \"hostingType\": \"localhost\"\n    },\n    \"staging\": {\n      \"hostingType\": \"gcp\",\n      \"gcp\": {\n        \"functionName\": \"yourapp-test\",\n        \"memory\": 128\n      }\n    },\n    \"production\": {\n      \"hostingType\": \"now\",\n      \"scripts\": {\n        \"start\": \"NODE_ENV=production node index.js\"\n      },\n      \"alias\": \"yourapp-prod\"\n    }\n  }\n}\n```\n\nTo deploy the production environment, simply run:\n\n```\nnowflow production \n```\n\nThis will deploy to [Zeit Now](https://zeit.co/now) and make sure that:\n- The _package.json_ that is being deployed will contain the _start_ script `\"NODE_ENV=production node index.js\"`.\n- The `env.active` property of the _now.json_ is set to `production`.\n- Once the deployment to [Zeit Now](https://zeit.co/now) is finished, it is automatically aliased to `yourapp-prod`. \n\nOn the contrary, to deploy the staging environment, simply run:\n\n```\nnowflow staging \n```\n\nThis will deploy to [Google Cloud Functions](https://cloud.google.com/functions/) and make sure that:\n- The `env.active` property of the _now.json_ is set to `staging`.\n- The _now.json_ contains a `gcp` property identical to the one defined in the staging configuration.\n\nNo more deployment then aliasing steps. No more worries that some environment variables have been properly deployed to the right environment. \n\n\u003e Learn more details on how NowFlow works in the [How Does NowFlow Work?](#how-does-nowflow-work) under the [FAQ](#faq) section.\n\n## Deploying To Google Functions or AWS\n\u003e IMPORTANT: Before deploying to Google Functions (GCP), YOU'LL HAVE TO ENABLE BILLING under the specific project hosting your function. Simply browse to your account ([https://console.cloud.google.com/](https://console.cloud.google.com/)), click on the _Cloud Functions_, and then click on _Enable Billing_.\n\nBefore deploying to GCP or AWS, you'll have to login first using:\n\n```\nnow gcp login\n```\n\nor\n\n```\nnow aws login\n```\n\nAfter using one of the above command, you'll be prompt to select a project within your GCP or AWS account. Once selected, your function will be deployed withing that project. \n\nTo change to another project, re-rerun the commands above.\n\n\n## Google Cloud Functions for Pub/Sub or Storage Events\n\nThis is only possible when using the [__*Webfunc*__](https://github.com/nicolasdao/webfunc) project that allows to write Express-like apps to run everywhere. There are examples on that project documentation [__*here*__](https://github.com/nicolasdao/webfunc#google-pubsub-topic--storage-trigger-based-functions). \n\n## The Most Minimal Setup\nYou must first create a __*now.json*__ file in the root of your project's directory as follow:\n```js\n{\n  \"env\": {\n    \"production\": {\n      \"alias\": \"yourapp-prod\"\n    },\n    \"test\": {\n      \"alias\": \"yourapp-test\"\n    }\n  }\n}\n```\n\nMake sure there is at least one environment defined under the _env_ property. Then simply run:\n\n```\nnowflow production\n```\n\nThe above will:\n1. Deploy your project to [Zeit](https://zeit.co/now) using the _production_ config defined in the _now.json_.\n2. Will alias that deployment using the alias defined in the _production_ config defined in the _now.json_ (i.e. 'yourapp-prod').\n\n## Skipping Aliasing\nIf 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:\n```\nnowflow production --noalias\n```\n\n## Modifying The package.json's \"scripts\" property For Each Environment\nAs 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. \n\n_now.json:_\n\n```js\n{\n  \"env\": {\n    \"production\": {\n      \"scripts\": {\n        \"start\": \"NODE_ENV=production node index.js\"\n      },\n      \"alias\": \"yourapp-prod\"\n    },\n    \"test\": {\n      \"scripts\": {\n        \"start\": \"NODE_ENV=test node index.js\"\n      },\n      \"alias\": \"yourapp-test\"\n    }\n  }\n}\n```\n\n```\nnowflow production \n``` \n\nIn 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.  \n\nIf you're using the serverless web framework [Webfunc](https://github.com/nicolasdao/webfunc), the above command will also make sure that the property `env.active` of the _now.json_ is also set to `production` before deploying. \n\n# FAQ\n## What Problems Does NowFlow Solve?\n\nTL;DR - It removes all the manual steps required before deploying to a specific environment (e.g. updating the `start` task in the package.json, changing the config in the now.json) and it adds support for Google Cloud Functions reacting to other events than an HTTPS request.\n\nOut-of-the-box, [__*Zeit now-CLI*__](https://zeit.co/now) does not offer any opiniated way to organize your variables on a per environment basis (e.g. database credentials, keys, ...). As of version 9.2.5, bugs still exist to deploy to AWS lambdas, and no support is provided to make functions deployed to Google Cloud to react to other events than an HTTPS request (e.g. Google Cloud Functions can react to Pub/Sub topics great for event-driven architecture, Google Storage or Firebase database changes). NowFlow enables all those features by simply configuring your traditional __now.json__. This is an opiniated design choice that contrast with maintaining multiple now.json files (e.g. now.dev.json, now.staging.json, now.prod.json, ...) mainly driven by the desire to make working on the localhost easier as well as complying to what the now infrastructure already understand. If your interested in multiple now.json per environment, check the awesome project created by [Jesse Ditson](https://github.com/jesseditson) called [now-deploy](https://github.com/jesseditson/now-deploy).\n\nTo understand a bit more how NowFlow works, let's have a look at all the manual steps that would be required before being able to deploy to a specific environment (e.g. staging vs production) using the simple `now` command line:\n\n1. Update the `start` script 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\"`).\n2. If you're deploying to [Google Cloud Functions](https://cloud.google.com/functions/), you might need to configure the `gcp` property in the _now.json_.\n3. If you're using the [Webfunc](https://github.com/nicolasdao/webfunc) serverless web framework, then you also need to set up the `env.active` property to the target environment in the _now.json_.\n4. Run the right command (e.g. `now` if deploying to [Zeit Now](https://zeit.co/now), and `now gcp` if deploying to [Google Cloud Functions](https://cloud.google.com/functions/)).\n5. Potentially _alias_ your deployment if your're deploying to [Zeit Now](https://zeit.co/now):\n\u003e - Update the `alias` property of the _now.json_ file to the alias name specific to your environment.\n\u003e - Run `now alias`\n\nThis process is obviously proned to errors. It is also tedious if you're deploying often. This is why we created __*now-flow*__. \n\n## How Does NowFlow Work?\nNowFlow 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:\n1. 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.\n2. Modify both your _package.json_ and your _now.json_ based on the environment configuration contained in the _now.json_.\n3. Invoke the `now` command (or `now \u003chostingType\u003e`) to deploy.\n4. If aliasing is required, then invoke `now alias`.\n5. If the deployment is successful, or if an error but is is successfully intercepted and displayed to the terminal, then:\n\u003e - Restore both the _package.json_ and your _now.json_ to their original state.\n\u003e - Delete the backup files created in step #1.\n\n# This Is What We re Up To\nWe 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](https://neap.co).\n\nOur other open-sourced projects:\n#### Web Framework \u0026 Deployment Tools\n* [__*webfunc*__](https://github.com/nicolasdao/webfunc): Write code for serverless similar to Express once, deploy everywhere. \n* [__*now-flow*__](https://github.com/nicolasdao/now-flow): Automate your Zeit Now Deployments.\n\n#### GraphQL\n* [__*graphql-serverless*__](https://github.com/nicolasdao/graphql-serverless): GraphQL (incl. a GraphiQL interface) middleware for [webfunc](https://github.com/nicolasdao/webfunc).\n* [__*schemaglue*__](https://github.com/nicolasdao/schemaglue): Naturally breaks down your monolithic graphql schema into bits and pieces and then glue them back together.\n* [__*graphql-s2s*__](https://github.com/nicolasdao/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.\n* [__*graphql-authorize*__](https://github.com/nicolasdao/graphql-authorize.git): Authorization middleware for [graphql-serverless](https://github.com/nicolasdao/graphql-serverless). Add inline authorization straight into your GraphQl schema to restrict access to certain fields based on your user's rights.\n\n#### React \u0026 React Native\n* [__*react-native-game-engine*__](https://github.com/bberak/react-native-game-engine): A lightweight game engine for react native.\n* [__*react-native-game-engine-handbook*__](https://github.com/bberak/react-native-game-engine-handbook): A React Native app showcasing some examples using react-native-game-engine.\n\n#### Tools\n* [__*aws-cloudwatch-logger*__](https://github.com/nicolasdao/aws-cloudwatch-logger): Promise based logger for AWS CloudWatch LogStream.\n\n\n# License\nCopyright (c) 2018, Neap Pty Ltd.\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n* 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.\n* 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.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL NEAP PTY LTD BE LIABLE FOR ANY\nDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\nON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://neap.co\" target=\"_blank\"\u003e\u003cimg src=\"https://neap.co/img/neap_color_horizontal.png\" alt=\"Neap Pty Ltd logo\" title=\"Neap\" height=\"89\" width=\"200\"/\u003e\u003c/a\u003e\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolasdao%2Fnow-flow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicolasdao%2Fnow-flow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolasdao%2Fnow-flow/lists"}