How to Create an Express Web-based Framework Application to be deployed in Node.js

Posted on

This is particularly written as a mean for learning or studying how to develop a web-based application using express as its main framework. It is used to develop a web-based application which is going to be deployed in Node.js. The main important factor is the availability of ‘express’ tool which can be retrieved by installing it first. The installation process for an example in an operating system which is in Ubuntu Linux, it is described in an article titled ‘How to Install Express in Ubuntu Linux operating system’ in this link. So, after the ‘express’ tool successfully installed, just type it in the command line as shown below :

express
user@hostname:~/nodejs/crud$ express
/usr/lib/nodejs/express-generator/bin/express:62
      program.confirm('destination is not empty, continue? ', function(ok){
              ^

TypeError: program.confirm is not a function
    at /usr/lib/nodejs/express-generator/bin/express:62:15
    at /usr/lib/nodejs/express-generator/bin/express:220:5
    at FSReqWrap.oncomplete (fs.js:82:15)
user@hostname:~/nodejs/crud$ 

The above command execution ends in failure because there isn’t any additional parameter given to the tool command which is actually specifying the name of the folder intended for the web-based application powered by express framework. Below is the actual help given by typing the command ‘express -h’ :

user@hostname:~/nodejs/crud$ express -h

  Usage: express [options] [dir]

  Options:

    -h, --help          output usage information
    -V, --version       output the version number
    -e, --ejs           add ejs engine support (defaults to jade)
    -H, --hogan         add hogan.js engine support
    -c, --css   add stylesheet  support (less|stylus|compass) (defaults to plain css)
    -f, --force         force on non-empty directory

user@hostname:~/nodejs/crud$

To create a project based on express framework for further deployment in Node.js, just execute the following command, for an example the name of the project which is going to be represented in the form of folder, let’s say ‘crud’ is shown below :

user@hostname:~/nodejs$ express todo

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

   install dependencies:
     $ cd crud && npm install

   run the app:
     $ DEBUG=my-application ./bin/www

user@hostname:~/nodejs$

As an information, the version of the express is shown below :

user@hostname:~/nodejs/crud$ express -V
4.0.0
user@hostname:~/nodejs/crud$

The next step will be executing ‘npm install’ which is mainly executed to be able to install package dependencies in the local installation of the web-based application powered by express framework.

6 thoughts on “How to Create an Express Web-based Framework Application to be deployed in Node.js

Leave a Reply