16

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

2
  • 4
    Express is nothing more than a well designed middleware system shipped with a really good set of middlewares. What most people experience writing in Express is the routing middleware (which incidentally is available as a stand-alone module). I'd suggest try using the plain-old HTTP module once to see how web programming works and doing routing manually yourself (like a simple switch statement). Then when you try Express, that good-old HTTP object is still there underneath it all if you need to do anything more advanced Commented Jan 22, 2017 at 3:30
  • Thanks for the input, this is the approach I have been taking. I have a basic understanding of the HTTP object and was just contemplating how I should proceed. Commented Jan 22, 2017 at 3:35

2 Answers 2

22

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).

Sign up to request clarification or add additional context in comments.

2 Comments

This was like music to my ears -- >Because express is so close to 'barebones' node, you can still write raw node code to work with it. I don't want to lose low-level control if I need it later on so this is great. Thank you.
@JohnSnow Can you direct me to a link/website/non-official documentation, which explains the use of Node and Angular without Express ?There is a requirement, but it is very difficult to get Angular-Node connections without Express
4

I'd like to add a few things here that might help you out. One thing that I have come to realize with software engineering is that there is never a "catch all" answer to a lot of these types of questions. Since each application is different, it is a good idea to look at the challenges and figure out what is the best tool for the job.

If you look at some of the performance tests done on the frameworks you notice that vanilla node is ultra performant. But most of the time your application isn't going to need to handle 8000 requests per second, and even if it does you can always scale your server horizontally nowadays. So you trade off a little bit of speed to gain a few benefits, such as:

  1. Much easier to write.
  2. The code base, in my opinion, is much easier to maintain.
  3. A lot of the little gotchas are taken care of by the framework so you don't have to be a Node.js god.
  4. Middleware.

Now, that doesn't mean that every single application should use express. A lot do because it is about as barebones as it gets. For instance, Walmart created Hapi because they claim that it is easier to maintain their code base with a 'configuration first' approach. So maybe if you are going to have this monster backend and a monster team, Hapi might be a good choice. If implementing something with real-time you might want to use something like socketcluster.io to help you scale websockets. It is all about picking the right tool for the right job.

That being said, there are advantages to building a server with vanilla Node, especially when learning to develop node apps. Since frameworks abstract a lot of the lower level stuff it takes away the opportunity to pick up some cool node tricks here or there. Or a lot of times if a framework is insufficient or an npm package is doing something weird it is good to have that knowledge of vanilla node under your belt to really understand what is going on. Having the skill of knowing how Node.js works is such a benefit when working with any framework.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.