Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vanilla Node vs Express

I'm wondering if some of you veterans could provide some guidance to some of us noobs.

Is there any advantage to writing vanilla Node over using Express? More specifically, any particular scenario where using Express will not be an option? And lastly for the tasks that you can use Express for, how deep should you go within the layers of abstraction to find out what's going on?

I mean there are plenty of people who can create robust and powerful web applications and they have no clue what the hell Express is actually doing for them.

Much appreciated

like image 790
JohnSnow Avatar asked Jan 22 '17 03:01

JohnSnow


People also ask

Is Express better than node?

js: Express is a small framework that sits on top of Node. js's web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your application's functionality with middle ware and routing.

Should I learn vanilla NodeJS?

It is important to understand how your system works. Therefore, it is a good experience for a developer to learn vanilla Node. js.

Why we use Express instead of node JS?

Node JS is a fast JavaScript runtime environment that we use to build server-side applications, but it does not know how to perform serving files, handling requests, and handling HTTP methods, so this is where express js comes in.

Do I need Express for node?

You don't need Express to create a basic HTTP server with Node. js. You can do that using the built in http module: const http = require("http"); const server = http.


1 Answers

If I were you, I'd use express.

To be honest, Express isn't much of a web framework. It's really barebones, and barely adds any functionality on top of Node core.

With this said, however, there are some benefits:

  • For better or worse, express has become the 'defacto' default web framework for Node developers. There's a lot of information about it.
  • Express provides some core things that are useful: a routing layer (to map functions to URLs), an 'application' object that you can bind variables to for settings, etc. -- and a simple middleware model that lets you add functionality to your app easily.
  • Because express is so close to 'barebones' node, you can still write raw node code to work with it. It isn't at all complicated like other 'larger' frameworks: django, rails, etc.
  • There are a TON of third-party express middlewares you can use which add all sorts of functionality to your site. This makes building your site easier.

Finally -- the biggest reason to use express is that it does almost nothing. It isn't significantly different from using raw node except that it provides some simple abstractions over lower level stuff.

Because express is so simple, it means you don't need to learn much to use it, and can write your app in whatever way you want (it doesn't enforce any sort of patterns).

like image 174
rdegges Avatar answered Oct 10 '22 18:10

rdegges