Unify Your Syncano Scripts With Global Variables

Devin VisslailliDevin Visslailli

Introducing our new Global Config. Consistent global variables across all of your server-side code saves you even more time to build your serverless app. Here's how you use it.

Code is always easier to write when you, well, write less! Of course, there are other things that may affect your productivity -- such as your programming environment or your cat dominating your keyboard -- but the whole purpose of things like variables or functions in code languages is to limit how many times you have to repeat your brilliance.

Here at Syncano, we tackled that common developer struggle in a way that we know will help you code faster. We’ve introduced Global Config Variables for your Scripts.

So, what are Global Variables?

I'm glad you asked! We're defining Global Config Variables as a global configuration JSON for all of your Scripts.

In a typical Script, you may have some Config variables set up so when you're writing your code, you only need to call CONFIG.variable_name (Node.js - other language examples available here) to access that value.

This is convenient, having a "Script-wide" variable and all, but what if you wanted to use that same value again in a different Script? Then you have to copy it over piece by piece (what a waste of time right?).

This is why we have decided to make a Config that's accessible globally across your Instance! That means any Script inside your Instance can access that value, which also means more time for your social life! Kidding, we all know that, as programmers, we sit in front of text editors all day ;)

No way! How do I start?

Although I doubt you had that much enthusiasm, it seriously would be refreshing! To set up a Global Config, you can follow the detailed guide in our docs here, or simply open your Dashboard and click on the "Global Config" link on the bottom of the left side-bar menu.

Then, type your config as a JSON like this!

{
  "key":"value",
  "api_key":"notTellingYou",
  "color":"Green"
}

Since it's a JSON, these variables can consist of anything you would normally use in a JSON object! This includes objects, arrays, strings, you name it.

Finally, just use them in your Script! Using the Config above, here's some example code:

// Javascript / Node.JS
var name = "Devin";  
var favoriteColor = CONFIG.color; // Here's your Global Config!

console.log("My name is " + name + " and I love the color " + favoriteColor + ".");

// Reponse:
// My name is Devin and I love the color Green.

Multiple Configurations

If you use a Global Config, and also a local Config inside a Script, just note that the local config will override the global one!

Well, enough time talking about it, go try it! Tweet @Syncano or @DevinViss (me) if you have any questions or want to reach out. Happy Coding!

Build powerful apps in half the time

Use our serverless platform to set up your backend in minutes.

Learn more

Developer Evangelist. Angular enthusiast, Early Adopter. New technology always inspires me, and I find myself constantly working to innovate and create integrations between the real world and tech.