49

I'm learning NodeJs from: http://www.tutorialspoint.com/nodejs/

And I cant understand what is the difference between using http module (get/post methods) vs using express module (get/post methods)

It seems that express module is rapid for development.

  • Are there advantages to use http module compared to express module ?
  • Are there advantages to use express module compared to http module ?

Thanks

Curious
  • 47
  • 6

1 Answers1

59

Express is not a "module", it's a framework: it gives you an API, submodules, and methodology and conventions for quickly and easily tying together all the components necessary to put up a modern, functional web server with all the conveniences necessary for that (static asset hosting, templating, handling CSRF, CORS, cookie parsing, POST data handling, you name it, it probably lets you use it).

The http API that's baked into Node.js, on the other hand, is just the http module: it can set up connections and send and receive data, as long the connections use the hypertext transfer protocol (with the relevant HTTP verb) and that's... well that's it. That's all it does.

They are completely different things. As many articles that you can find by searching the web for the details on both will tell you.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
  • 4
    Is there any capabilities that can be developed by express framework and not by http module ? (and vice versa ?) –  Aug 31 '15 at 04:01
  • 12
    @Boom - the Express module is built on top of the http module. It uses the http module for managing the incoming http connections. But, it adds a ton of additional functionality on top of the http module. That is the point of it. For example, if you want to server whole directory of static files (like CSS files or script files) from your node server, that can be done with one line of code in node.js, but would take a lot more code with only the http module. – jfriend00 Aug 31 '15 at 04:26
  • What is meant by "submodules" here? – Joel Peltonen Sep 01 '21 at 13:31
  • https://expressjs.com/en/resources/middleware.html (six years ago, many of those were part of express itself, not separately installable packages) – Mike 'Pomax' Kamermans Sep 01 '21 at 15:36