How to Create An Express Application in Linux Ubuntu using EJS Template Engine

Posted on

This article will show how to install an application using Express framework in Linux Ubuntu. Actually, this article will use Linux Ubuntu 18.10 as the operating system to perform the installation. In this article, creating the application will be done using a generator tool at first. The generator tool is the Express Generator where the information for the installation exist in this link. The application itself will use an EJS template engine. Basically, according to this link, there are several template engines available. According to that link, some popular template engines that work with Express are Pug, Mustache, and EJS. The Express application generator uses Jade as its default, but it also supports several others. In this context, the template engine will use ‘ejs’ as its template engine. The following is the step for creating the application powered by Express Application using EJS template engine :

1. Install Express Generator. The link is available to get the information.

  1. Execute the following command to generate the application skeleton :
express --view=ejs myapp

The above command is the command to create an application with the name of ‘myapp’ using ‘ejs’ as the template engine. For an example, the following is the execution of the above command pattern :

user@hostname:~/express$ express --view=ejs myapp

   create : myapp/
   create : myapp/public/
   create : myapp/public/javascripts/
   create : myapp/public/images/
   create : myapp/public/stylesheets/
   create : myapp/public/stylesheets/style.css
   create : myapp/routes/
   create : myapp/routes/index.js
   create : myapp/routes/users.js
   create : myapp/views/
   create : myapp/views/error.ejs
   create : myapp/views/index.ejs
   create : myapp/app.js
   create : myapp/package.json
   create : myapp/bin/
   create : myapp/bin/www

   change directory:
     $ cd myapp

   install dependencies:
     $ npm install

   run the app:
     $ DEBUG=myapp:* npm start

user@hostname:~/express$ 

3. Check the result by executing the following command :

user@hostname:~/express$ ls
myapp
user@hostname:~/express$ cd myapp/
user@hostname:~/express/myapp$ ls 
app.js  bin  package.json  public  routes  views
user@hostname:~/express/myapp$ 

Just use the normal command as in the above command execution. A folder with the name of ‘myapp’ exist along with the content inside of it. It is the application skeleton as a result of the above express generator execution command.

Leave a Reply