NODEJS

Using Express

Article by:
Date Published:
Last Modified:

Overview

Express is a web application framework for node. The Express framework itself uses Connect for some of it’s functionality, a middleware framework for node.

It’s website is http://expressjs.com/.

Installing

You can install Express with NPM (node package manager) using the following command:

1
$ npm install express

This will install express into the current directory under the standard node packages folder.

Basic Web Server

The following code shows how to make a basic web server with Express. Notice how it is different from the basic web sever using plain node.

1
2
3
4
5
6
7
8
var express = require('express');
var app = express();

app.get('/', function(req, res){
    res.send('hello world');
});

app.listen(3000);

To run this, save the code as a .js file, and instruct node to run this file from the command line by typing node filename.js.


Authors

Geoffrey Hunter

Dude making stuff.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License .

Tags

    comments powered by Disqus