To get started with ExpressWebJs, you will need to install
Node.js >= v14.15.1 and npm >= 6.0.0
Because 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 project, you can use
npx expresswebcli new command, followed by your project name and --ts or --typescript.
--typescript flag enables Expresswebjs to generate the typescript version.
npx expresswebcli new myProjectName --typescript
Or you can use ts inplace of typescript
npx expresswebcli new myProjectName --ts
You can decide to install expresswebcli globally via npm like so:
npm install -g expresswebcli
Then run the below command to create your project.
expresswebcli new myProject --ts
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, move into your project directory or use the command below in your terminal.
Once you do that, you can now install all dependencies by running 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 project to see all maker commands.
ts-node maker -h
# Database Setup
ExpressWebJs makes interacting with SQL and NOSQL databases extremely easy across a variety of supported database.
- Amazon Redshift
- MicroSoft SQL
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 Config/database.ts 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 by updating these values:
DB_SHOULD_CONNECT = true; DB_CONNECTION = mysql; DB_HOST = localhost; DB_PORT = 3306; DB_USER = database_user; DB_PASSWORD = database_password; DB_DATABASE = database; 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 by updating these values.
DB_SHOULD_CONNECT = true; DB_CONNECTION = mongoose; DB_HOST = localhost; DB_PORT = 27017; DB_USER = database_user; DB_PASSWORD = database_password; DB_DATABASE = database; 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 config directory Config located in the root directory. 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 Config/app.ts file and its documentation. It contains several options you may wish to change according to your application.