Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

atlassian-connect-express 5: add parameters to config.json


This article is based on the previous article.

You can find the source code for the article here.

You can watch the video for this article here.

In this article we will discuss how to add your own parameters to config.json file.

As you remember backend/config.json contains parameters which are passed to the application when the application is starting. These parameters are passed by developers or administrators, that is why these parameters are not hardcoded somewhere in the code, but are placed in the config.json file which is easy to edit.

You may need your own parameters if you introduce logic which depends on some switchers. In this case you can add the switchers to the config.json file. Or if you call some kind of Rest Api and the url of the Rest Api is different for development and production. In this case you can add the url of the Rest Api to the config.json. Or if you are connecting to some external application and you need to provide the user name and the token to connect to this system.

We will be changing the development section of config.json. The same can to be done to the production section. Here is our development section:

    "development": {
        "port": 3000,
        "errorTemplate": true,
        "store": {
            "adapter": "sequelize",
            "dialect": "sqlite3",
            "type": "memory"
        "localBaseUrl": ""

First, let’s make our app read the port and localBaseUrl parameters from environment variables:

"development": {
        "port": "$PORT",
        "errorTemplate": true,
        "store": {
            "adapter": "sequelize",
            "dialect": "sqlite3",
            "type": "memory"
        "localBaseUrl": "$APP_URL"

As you can see the port value will be taken from the PORT environment variable and the local base url from APP_URL environment variable.

Now let’s add new parameters to our config file. We will add a REST API url and credentials for our external app:

"development": {
        "port": "$PORT",
        "errorTemplate": true,
        "store": {
            "adapter": "sequelize",
            "dialect": "sqlite3",
            "type": "memory"
        "localBaseUrl": "$APP_URL",
        "restApiUrl": "",
        "externalApp" : {
            "username" : "myusername",
            "token": "mytoken"

I created the restApiUrl parameter which has just a string value and the externalApp parameter the value of which is a json. I could have also created these parameters as variables like the port and externalApp parameters, but for the sake of simplicity I will not do it.

Now let’s add some code to our application to read all these parameters:

http.createServer(app).listen(port, () => {
  console.log('App server running at ' + addon.config.localBaseUrl());
  console.log(`port: ${addon.config.port()}`)
  console.log(`localBaseUrl: ${addon.config.localBaseUrl()}`)
  console.log(`restApiUrl: ${addon.config.restApiUrl()}`)
  console.log(`externalApp: ${JSON.stringify(addon.config.externalApp())}`)

As you can see to read parameters you need just to call addon.confg.<the name of the parameter>().

The externalApp parameter we defined as json, that is why an object in json format is returned. And that is why we stringify the output to see the output in the terminal: JSON.stringify(addon.config.externalApp())

Let ‘s run our application. As a result we will have an error:

Error: listen EADDRINUSE: address already in use $PORT

It means that we did not initialize our environment variable PORT. Let’s initialize both the PORT and APP_URL variables:

export PORT=3000
export APP_URL=

Now let’s run our application again and here is the output:

pport: 3000
externalApp: {"username":"myusername","token":"mytoken"}

That is it. Now we can define our own parameters and read the parameters in our app.

Thank you for reading!

1 comment

Mohammed Amine Community Leader Jun 04, 2021

Interesting content, thank you @Alexey Matveev _Appfire_ 


Log in or Sign up to comment
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

130 views 1 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you