Uploading a Zip File

The zip upload feature lets you create a Lapp using code from multiple files. This approach allows you to keep your code segregated for different functionalities and also makes it easier to update. For example, you may want to keep a static JSON file separate from a main.js file for better readability and maintenance.

 

Get Started

To get started, download the main.zip file.

download main.zip

The main.zip file has sample code that will instruct you on how to write your first Lapp. It shows you how to –

  • Create a ‘main‘ function.
  • Create settings.
  • Store a value in the database.
  • Retrieve that value from the database.
  • Create logs.

For more details, see How to Write Code in Lapps.

 

Upload a Zip File

To upload a zip file, simply drag and drop the file to the file upload area (highlighted below). You can also click the Upload link and select the file from the file browser.

upload a zip file

Once you’ve uploaded the zip file, hover your cursor Publish button and click Test Environment. You will receive your API URL for the test environment.

publish a lapp after zip upload

Note: You can only publish the Lapp to Live once it is published to Test.

 

Rules for Zip Upload

  • There should be at least one file by name main.js. This file must have a main function with the following signature: function main(Object queryString, Object body, function callback) { } 
  • Files with the following names are used internally so you can’t have them at the root level of your zip file. However, you can include them at the sub-folder level.
    • index.js
    • dbstore.js
    • helper.js
    • log.js
    • setting.js

 

Settings

Settings can be uploaded optionally. Please name the file as setting.json. You can download the sample file here to understand the schema. Do not forget to place ‘Test’ and ‘Live’ properties, though it is not mandatory to place their values.

Alternatively, you can upload the zip file and then create the settings from the Settings tab on the Lapps UI –

Adding Settings after uploading zip

Note: When you download the zip file, for security reasons, you won’t see the values of your settings in the setting.json file. You can view them by navigating to the Settings tab instead.

 

Compatible Libraries

You can use the following libraries out of the box –

  • Request for making http/https request calls. Please there is no need to ‘require’ this module in main.js file.
  • Date-fns for date-time manipulation.
  • Mustache for implementing mustache template system.

 

Next Steps