Why combine http module with express module

Viewed 5117

Hello guys i'm new to node js and started researching and working on some tutorials. I just want a better understanding or clarification on a doubt i had. So i came across the in built module http. This helps in creating a a basic web server. Now express module is a web framework that is built on top the http module that makes it easy using a fully wedged web server without reinventing the wheel. Now I came across this code:

var express = require( 'express' )
, http = require("http")
http.createServer( options, function(req,res)
{
  app.handle( req, res );
 } ).listen(8080);

But in express one could simply just do this

 var express = require('express');
 var app = express();
 app.listen(8080, function() {
  console.log('Listening on ' + 8080);});

What's the difference between both? Don't they both accomplish the same thing. If not what's the difference and advantage of using the first approach. Should one adhere to the first approach as it's a good programming practice. That's my doubt as i just want a clear understanding if there's any difference.

1 Answers
Related