Getting Started with Express.js

Follow the steps below to create and run a default web application using Express.js.

Express-DefaultSite

1. If you have not already done so, download and install Node.js. As of this writing, the latest version is available for download at the URL “https://nodejs.org/en/”. Alternately, if you are running a Linux operating system, open a command-prompt and use the package management tools “apt-get” or “yum” to install the “node”, “nodejs-legacy”, and “npm” packages. For example, on a Debian-based disto like Ubuntu, you might enter “apt-get install node npm nodejs-legacy”, while on a RedHat-based disto like CentOS, you might instead enter something like “yum install node npm” (please note that I have not tested this on a RedHat-based distro).

2. In any convenient location, create a new directory named “ExpressTest”.

3. Open a command prompt window and navigate to the newly created “ExpressTest” directory. At the command prompt, enter the following commands, making sure that each completes with no errors:

	npm install express-generator -g
	express ExpressTestApp
	cd ExpressTestApp
	npm install
	npm start

4. Open a web browser and navigate to the URL “http://localhost:3000”. Verify that a page containing the message “Welcome to Express” is displayed.

5. Within the ExpressTestApp directory, navigate to the subdirectory “views”, and locate the file “index.jade” within it. Open index.jade in a text editor and find the text the “Welcome to” within it. Customize that text in some small way and save the file. Then reload the URL “localhost:3000” to see the changes take effect.

Advertisements
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

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