DEV Community 👩‍💻👨‍💻

Ibrahim Ragab
Ibrahim Ragab

Posted on

Write Node server with ES6 Classes

I'm learning Node.js and all back-end stuff and I see there's one way to implement a server by import the module and declare the path and the app and so on.

I wrote a simple server using ES6 classes and it looks like this:

When I log the response it seems typical to the regular server, check the repository below you can clone and run it.
I need answers about what is the advantages and the difference.

GitHub logo Yuribenjamin / node-server-class

Such a node server is written with ECMAScript 2015 (ES6)


Such a Express Node server is written with ECMAScript 2015 (ES6) JavaScript classes.

Top comments (2)

fibric profile image
Denny Trebbin

In my opinion, it's not the best example to show the OOP style server code.

Server.core + performanceHooks -> Babeljs ->

Server.listen + performanceHooks -> Babeljs ->

Expressjs + performanceHooks -> Babeljs ->

I'm not a fan of OOP, and I'm not strictly bound to pointless or functional programming, but the given an example is, at least to me, not a good example.

Also, the compiled code isn't shorter or faster than the code we've used writing for years.
The Server.listen example is as fast as Expressjs while Server.core example is up to 4 times slower.

Note: benchmarks are always wrong because so many invisible (implicit) variables have an impact on them.

yuribenjamin profile image
Ibrahim Ragab

Thanks Denny I understand now

Stop sifting through your feed.

Find the content you want to see.

Change your feed algorithm by adjusting your experience level and give weights to the tags you follow.