# Installation

We want it to be as easy as possible getting started with ExpressWebJs, that's while we have a command line tool to help you install ExpressWebJs.

To start your new project, you can use npx expresswebcli new command, followed by your project name. Example:

 npx expresswebcli new ritetech

Or you can install it globally via npm like so:

npm install -g expresswebcli

and then run

  expresswebcli new ritetech

to create your new ritetech application.

Make sure to add the npm system-wide node_modules/.bin directory to your $PATH to be able to access the installed binary.

Once that is done,

 cd ritetech

Once you do that, you can now install all dependencies by running npm install.

 npm install

In version 2 upwards, MAKER command line interface is included in ExpressWebJs. Maker exists at the root of your application as the maker script and provides a number of helpful commands that can assist you while you build your application.

Run the following code once you have created your new application to see all maker commands.

  node maker -h

# Database Setup

ExpressWebJs makes interacting with SQL and NOSQL databases extremely easy across a variety of supported database. Befor we continue, if you've not created your .env file, quickly do that by copying example.env to .env file or you can run the following command in your terminal:

   cp example.env .env

Now that our .env file is ready, the configuration for ExpressWebJs database is located in App/Config/database.js configuration file. In this file, you may define all of your database connections, as well as specify which connection should be used by default. Most of the configuration options within this file are driven by the values of your application's environment variables.

# SQL Database configuration

You can easily configure your environment variables to point to your database by placing the connection values in the .env file: Let's connect to mysql database

   DB_SHOULD_CONNECT=true               //should connect to database
   DB_CONNECTION=mysql                 //database
   DB_HOST=localhost                  //database host
   DB_PORT=3306                      //database port
   DB_USER=                         //database username
   DB_PASSWORD=                    //database password
   DB_DATABASE=network-provider
   DB_USENEWURLPARSER=true
   DB_USEUNIFIEDTOPOLOGY=true
   DB_USECREATEINDEX=true

# NOSQL Database configuration

You can configure your nosql database environment variables to point to your database by placing the connection values in the .env file: Let's connect to mongoDB

   DB_SHOULD_CONNECT=true                  //should connect to database
   DB_CONNECTION=mongoose                 //database
   DB_HOST=localhost                     //database host
   DB_PORT=27017                        //database port
   DB_USER=                            //database username
   DB_PASSWORD=                       //database password
   DB_DATABASE=network-provider
   DB_USENEWURLPARSER=true
   DB_USEUNIFIEDTOPOLOGY=true
   DB_USECREATEINDEX=true

Once that is done, you can now run your application with:

  npm run dev

# Initial Configuration

ExpressWebJs configuration files are stored in the application config directory App/Config. Each option is documented, so feel free to look through the files and get familiar with the options available to you.

You are free to get started developing! However, you may wish to review the App/Config/app.js file and its documentation. It contains several options you may wish to change according to your application.

# Maintenance Mode

You can switch your application to maintenance mode in App/Config/app.js file in maintenanceMode section. When your application is in maintenance mode, a default message "Application is in maintenance mode" will be sent for all requests accessing your application. This makes it easy to "disable" your application while it is updating or when you are performing maintenance. A maintenance mode check is included in the default middleware stack for your application. If the application is in maintenance mode, a MaintenanceModeException will be thrown with a status code of 503.

To enable maintenance mode, change the mode in maintenanceMode section to true:

  /*
  |--------------------------------------------------------------------------
  | Application maintenance mode
  |--------------------------------------------------------------------------
  | Mode ==> Determine if application is in maintenance mode or not. Default value is false
  | Message ==> The message to render while in maintenance mode.
  | Retry ==> The number of seconds after which the request may be retried
  | Endpoints ==> The endPoints that should be reachable while maintenance mode is enabled.
  |            endpoints example: ['api/users','api/accounts']
  |
*/
  maintenanceMode: {
    mode: true, //enable and disable maintenance mode
    message: "Application is in maintenance mode.",
    retry: 50,
    endPoints: [],
  },

You can also specify the endpoints you want to be accessable while your application is in maintenaince mode. Let's make 'api/users' and 'api/accounts' to be accessable like so:

   maintenanceMode: {
    mode: true, //enable and disable maintenance mode
    message: "Application is in maintenance mode.",
    retry: 50,
    endPoints: ['api/users','api/accounts'],
  },