Installing express js and setting up an express application

Hello everybody and good evening. Now today I am going to discuss (form a practical prospective) about a node.js framework, which is called express js. You can find the framework at http://expressjs.com/. So let’s install the framework.

Assume that you have installed node.js already. Node.js has a command line tool called npm, which installs node.js packages. We will use npm to install express framework. (I will discuss about node in a latter post. I hope)

In the command prompt, type:

        npm install -g express

This will install express framework globally in your PC.  Now you can use express per project basis, but in this post I will focus on express command line tool.  Now type in command prompt,

        express -h

you will see the uses and option of express in command prompt.

Now we will create an express app. We will use jade template engine which is the default option for creating an app with express command tool. Just go to a suitable place in your PC, better with command prompt, if not then open command prompt at that folder and type in command prompt,

        express myApp

now, install dependencies (as instructed which you executes the last command)

        cd myApp
         npm install

npm install command will install the dependencies at node_modules folder. You can check that. Also, you can see package.json file. That file stores the dependency package for this project.

ok, now type,

        node app

now at the command prompt you will see express server is running. Open browser, type, localhost:3000 (you will see in command prompt, if you are using windows 7, you can use 127.0.0.1:3000, I have not tested in windows 8). You will see the output in browser.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s