Live data from Hacker News

Node.js Fundamentals: Web Server Without Dependencies

blog.bloomca.me

21–30 of 44 posts

Re: Node.js Fundamentals: Web Server Without Dependencies

#22
post #19

Earlier quoted context omitted.

IIRC before nodejs+express the req/resp/next paradigm and middleware paradigm had never been so accessible. Other frameworks had it of course, but it was often hidden behind layers of abstraction or little quibbly bits. Express gave you just what you needed for both middleware and handlers: app.get('/', function(req, res, next) { res.send('hello world'); }) For comparison, flask: @app.route("/", method='GET') def hel…

I agree for the most part, except comparing node/express to Rails: node's equivalent in the Ruby world would the Sinatra, which is about as succinct than node.

You're right -- I didn't mean to compare them in terms of size/functionality but rather just as other options that were out there and why people might have picked node in the presence of other good alternatives.

Re: Node.js Fundamentals: Web Server Without Dependencies

#23
Great article. Anyone working with Node.js should be familiar with these fundamentals. It also demonstrates the simplicity (and dare I say "elegance", though that's subjective..) of Node.js and its concepts.

These days my favorite library for writing an HTTP server is micro [0] (and a few middlewares). I like how it provides a minimal, functional layer of abstraction.

[0] https://github.com/zeit/micro

Re: Node.js Fundamentals: Web Server Without Dependencies

#24

Performance is also a major advantage. Express is extremely slow compared to a basic "native" API without dependencies. If you check out the results in numbers, you'll be amazed.

Please post some citations to back up your performance claims. I haven’t found strong numbers online.

Re: Node.js Fundamentals: Web Server Without Dependencies

#25

Performance is also a major advantage. Express is extremely slow compared to a basic "native" API without dependencies. If you check out the results in numbers, you'll be amazed.

Express is not actually that much slower - I tested it when I wrote a light-weight Express replacement[1] for my own use (which was mainly about reducing the number of dependency packages from 40+ to 2). IIRC the slowest part was the default 404 router.

I was testing with only a few routes though - maybe it gets slower with more (IIRC Express architecture is that all routes are run in serial, so those defined last have to go through all the previous routes first). That and I didn’t add any latency to my tests to make it like the real world - that always has an interesting effect on results. :) Maybe I should re-run those tests for fun …

[1] https://github.com/borisovg/node-web-framework/blob/master/R...

Re: Node.js Fundamentals: Web Server Without Dependencies

#26
Not 100% related to the article but koa with its maybe 300 LoC is hardly a dependency. However in general nodejs projects definitely suffer from dependency bloat. I encourage anybody to try for themselves to go through node_modules in their own projects, it’s quite englightning to see the scale of the unnecessary, duplicated, reimplementated in different ways crap there. Conscious aim at shallow, minimal or no dependency in packages and end apps is definitely something good; less than 5s installs, code audits, more healthy projects in general. I’m not saying it’s always possible or better to trim the code fat, but if you’re aware of dependency tree single root dep introduces you’re usually able to cut it down a lot.

Re: Node.js Fundamentals: Web Server Without Dependencies

#27

IMHO articles like this played a major role in Node's initial success. After years of working with ever-growing frameworks with huge learning curves, it was so refreshing to get your first thing running in few seconds. Felt like basic in the 1980s or PHP in the late 1990s.

IIRC before nodejs+express the req/resp/next paradigm and middleware paradigm had never been so accessible. Other frameworks had it of course, but it was often hidden behind layers of abstraction or little quibbly bits. Express gave you just what you needed for both middleware and handlers: app.get('/', function(req, res, next) { res.send('hello world'); }) For comparison, flask: @app.route("/", method='GET') def hel…

People love Rails/Django because of active records ORM.

No idea if JavaScript has similar ORM

Re: Node.js Fundamentals: Web Server Without Dependencies

#28

Not 100% related to the article but koa with its maybe 300 LoC is hardly a dependency. However in general nodejs projects definitely suffer from dependency bloat. I encourage anybody to try for themselves to go through node_modules in their own projects, it’s quite englightning to see the scale of the unnecessary, duplicated, reimplementated in different ways crap there. Conscious aim at shallow, minimal or no depend…

Koa is appreciated to it's true value by the community.

Express was the most popular at the start and after StrongLoop got acquired by IBM it made sense for everyone that express was the foundation of Node.JS.

It's sad knowing how much bloated express is and every single Node.js library uses it from Next to GraphQL server etc...

Re: Node.js Fundamentals: Web Server Without Dependencies

#29

Performance is also a major advantage. Express is extremely slow compared to a basic "native" API without dependencies. If you check out the results in numbers, you'll be amazed.

For performance, I prefer Fastify rather than Express (https://www.fastify.io).

Re: Node.js Fundamentals: Web Server Without Dependencies

#30
post #24

Performance is also a major advantage. Express is extremely slow compared to a basic "native" API without dependencies. If you check out the results in numbers, you'll be amazed.

Please post some citations to back up your performance claims. I haven’t found strong numbers online.

> Please post some citations to back up your performance claims.

According to TechEmpower benchmark[0],Node.js-MySQL is two time faster than express-mysql.

Others benchmarks of TechEmpower tend to point exactly the same result in terms of performance for express.

[0] https://www.techempower.com/benchmarks/#section=data-r17&hw=...

Post reply on HN