We are thrilled by all of the excitement that we see around Parse Server and Cloud Code development. We have seen many Cloud Code success stories, and at the same time challenges, for the Parse and SashiDo developers.
Today I would like to tell you about one significant addition to the SashiDo Platform, the Environment Variables, and the new Cloud Code Development Model.
Environment Variables
Every developer desires to build code that can be used in more than one environment. To do this in a clean and reusable fashion, the code should be able to accept configuration values at runtime. The configuration values customize the environment for the code: service credentials, custom URLs, file paths, and so forth. For example, many projects have distinct configurations for their development, test, and production environments.
In brief, using the Environment Variables is the best approach to design your code to work like an appliance.
Check out the 12factor config if you're interested in this field.
Parse.Config vs Environment Variables
Many of you who have some experience with Parse would say: "We have the Parse.Config
, why we need another way to configure our apps?"
Yes, this is almost correct, but not really. Parse.Config
was built mainly for configuring the Front-end side of your applications, for things like feature flagging, changing the look and feel settings or managing some contact information.
Parse.Config
is a fantastic way to configure your application on the fly, but there few issues that make the Parse.Config
inappropriate for every case. For example, every setting in the Parse.Config
is public readable, in other words, any sensitive data should not be stored there!
All of this means that you need some secure way to store your credentials for Twilio
, Stripe
, Mailgun
or any of the services you use in the Cloud Code.
In brief, the Environment Variables are the Parse.Config
alternative for configuring the Back-end part of your application securely.
How to use the Environment Variables in the app's Cloud Code
Well, since the Environment Variables are very popular and they are used almost everywhere, NodeJS supports them as well. Let me give you an example of how the Environment Variables change your code.
Configuring Mailgun without Environment Variables
var mg = mailgun.client({
username: 'api',
key: "some_hardcoded_Key",
public_key: "some_hardcoded_Public_Key"
});
And here is how the code will look like with Environment Variables
.
var mg = mailgun.client({
username: 'api',
key: process.env.MAILGUN_API_KEY,
public_key: process.env.MAILGUN_PUBLIC_KEY
});
As you can see in the first example, the code has the hardcoded credentials which make it not portable and insecure.
Setup your Environment Variables in the SashiDo's Dashboard
From the example above you already know how to use the Environment Variables in your application's Cloud Code. Adding them to the app environment is straightforward too. You only need to go to: Application
-> Runtime
-> Environment Variables
When you're done click on the Save & Deploy button, and that's it! :)
Fin
Environment Variables bring a new level of simplicity to work with the Parse Server Cloud Code. I hope you'll enjoy it.
Happy Cloud Coding!
Top comments (0)