Skip to main content

.env

Configure notification channels and required features

Ensure you completed the installation

The installation process can be found here.

Extra vastly configurations are required for the API to run.

Note

At this point, the API can be run and consumed by a client, but we have no registered users or any notification channel setup. If your project does not require users in the system then you can skip this configuration but this will rarely be the case

About

The env file contains all globally used Vastly variables, it also defines Node.js development and production environment. Once Vastly setup is completed the provided data is saved in the .env file.

Below is a list of variables that Vastly automatically saves into the .env file during the installation process

1. DBSTRING - stores the MongoDB connection string provided during setup
2. DBUSER - stores the Database user provided during setup
3. DBPASSWORD - stores the Database password provided during setup
4. TOKENSECRETE - JWT secret provided during setup
5. TOKENDURATION - token lifeperiod provided during setup
6. COOKIEDURATION - Cookies lifeperiod provided during setup
6. INSTALLED - Set to true by the API if the setup process finalizes without an error
7. INSTALL_KEY - A uniquely generated id that marks a successful installation

Notification

Vastly is equipped with two notification systems, SMS and Emails. By default, only one channel can be used at a time, but this can also be easily configured.

Important

Notifications are configured per your project requirements, if you require users to register using emails, then you will just need to configure the email channel.

Setup Emails

Vastly email system is built using NodeMailer and configured in an Email Class, read more about emails here

The Email channel is configured using the following variables.

1. EMAILUSER - SMTP email User
2. EMAILPASSWORD - SMTP email Password
3. EMAILHOST - SMTP email Host
4. EMAILPORT - SMTP email Port
5. EMAILPORT - Label of who has sent the email

Examples

Below are some configuration Examples for email

EMAILUSER=user@example.co.ke
EMAILPASSWORD=xxxxxxxxxxxx
EMAILHOST=mail.example.co.ke
EMAILPORT=9090
EMAILFROM=admin@example.co.ke

Development emails

In development mode Vastly will not send live emails and will instead use mailtrap.

To instantly send emails upon setup, then update the NODE_ENV variable to be production.

NODE_ENV=production

To configure a mailtrap account, navigate to a file located at utils\email.js from the root folder.

The configurations are set in a createTransport() method

email.js
----
createTransport() {
if (process.env.NODE_ENV == "development") {
return nodemailer.createTransport({
//XXX DEVELOPMENT EMAILS
host: "smtp.mailtrap.io",
port: 2525,
auth: {
user: "xxxxxxxxxxxx", // Get from your account dashboard
pass: "xxxxxxxxxxxx", // Get from your account dashboard
},
});
}
}

Setup SMS

Vastly SMS system is built using MessageBird and configured in an SMS Class, read more about SMS here

The SMS channel is configured using the following variable.

1. MESSAGE_BIRD_KEY - Live or Test API key from messagebird

Examples

Below is a configuration Example for SMS

MESSAGE_BIRD_KEY=uMVyVxxxxxxxxxxIempOfq4zQ
Note

API errors that are handled by the error controller, are automatically emailed to the system admin or a set email address, if you don't use Emails then you will need to update or set how error notifications are sent to the admin, You can do so Here

User Management

By default Vastly has two user roles, the Admin and a user. Adding Roles and users can be done before the setup process here

Setting the default role a user is assigned during user registration is done using the following variable.

DEFAULT_REG_USER - Defines the role name a newly registred user gets

Default value:

DEFAULT_REG_USER=USER

Jest Unit Tests

Note

Before initializing a test ensure to setup Jest correctly as explained here.

Vastly ships with 2 Jest unit tests for the Authentication REST api.

The unit tests are configured using the following variables.

JEST_DB - The database name Jest will use for authentication purposes

Jest database runs using the provided MongoDB connection string, the database is automatically deleted once tests are completed.

JEST_TESTING_MODE - Defines if testing is being done or not

The testing mode variable is crucial as it blocks all Vastly notification channels when carrying out the tests

Examples

JEST_DB=jestDB
 JEST_TESTING_MODE=false

Payment Gateways

Vastly is shipped with 3 payment gateways.

Note

You can configure any payment gateway you need, or none if you dont require any. More information is available in the Payment REST docs

Stripe

To use Stripe you will need to configure the following two variable

STRIPE_WEBHOOK_SECRET - a stripe webhook secret
STRIPE_SECRET_KEY -  a stripe API key

Examples

STRIPE_WEBHOOK_SECRET=whsec_jvtexxxxxxxxxxxxxxxxxiToTgKg1
STRIPE_SECRET_KEY=sk_xxxx_51JMWK4CxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxromtdXwC4Fdmq5wgW000kGraBYO3

PayPal

To use PayPal you will need to configure the following three variable

PAYPAL_MODE - defines paypal environment
PAYPAL_SECRET_KEY -  a PayPal API secret
PAYPAL_CLIENT_ID -  a PayPal API ID

Examples

PAYPAL_MODE=sandbox
PAYPAL_SECRET_KEY=ENOh6iszB3_uxxxxxxxxxxxxxxxxxxxxxxxxxxIWEl_QbUSktD6jlKPinGvLA
PAYPAL_CLIENT_ID=ATOz8QuA_5XyoDeaxxxxxxxxxxxxxxxxxxxxxxxxxxxxBgNXpRlFMIRc-5swTT6F

PesaPal

To use PesaPal you will need to configure the following two variable

PESAPAL_CONSUMER_KEY -  a PesaPal API key
PESAPAL_CONSUMER_SECRET -  a PesaPal API secret

Examples

PESAPAL_CONSUMER_KEY=PxxxxxxxxxxxxVO1Wbx3d80j
PESAPAL_CONSUMER_SECRET=xF2txxxxxxxxxxxxxxe9KFGs=

More

GOOGLE_CLIENT_ID

Used for google authentication, this enables user to register or login using their google account.

More information is available in Authentication REST docs

Example

GOOGLE_CLIENT_ID=390511252259-xxxxxxxxxxxxxxxxxxxxxontent.com

NODE_TLS_REJECT_UNAUTHORIZED

Used to resolve Node.js self assigned security certificate

Read more Here

Hurrah

At this point all Important configuration are set. You can now start Vastly using node server.js or provided package.json scripts