Skip to content

JavaScript Style Guide

Daniel Di Sarli edited this page Nov 8, 2022 · 3 revisions

Environment variables

Your demo application should read any configuration variable (e.g., Project ID, API Token) from the environment. Typically, the user will provide a .env file which will contain the environment variables, and your program will look for this file in its same directory.

You should also provide a file called env.example (without initial dot) which will act as a template. Example for env.example:

# Project ID. Copy it from the API Credentials in your SignalWire Space.
# Example: 7b98XXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
PROJECT_ID=

# API Token. Copy it from the API Credentials in your SignalWire Space.
# Example: PTda745XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
API_TOKEN=

# SPACE_URL. Copy it from the API Credentials in your SignalWire Space.
# Example: spacename.signalwire.com
SPACE_URL=

Please only include the relevant fields.

To read the .env file from your application, add the following line at the very top of the main file:

require("dotenv").config();

This requires the dotenv package (npm i dotenv).

Automated formatting

To ensure a consistent look and the absence of errors, it is often advised to run an automated formatter. We support "prettier": you can use it as a VS Code plugin, or from the command line, like this:

npx prettier --write path/to/my/demo

Clone this wiki locally