Live data from Hacker News

Node.js Fundamentals: Web Server Without Dependencies

blog.bloomca.me

31–40 of 44 posts

Re: Node.js Fundamentals: Web Server Without Dependencies

#31

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…

> innovations like the amazing standard library

Excuse me?

Re: Node.js Fundamentals: Web Server Without Dependencies

#32

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…

People love Rails/Django because of active records ORM. No idea if JavaScript has similar ORM

Its not as opinionated as rails/django but there's typeORM among others

Re: Node.js Fundamentals: Web Server Without Dependencies

#33

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…

700 LoC and 40 of its own dependencies.

Re: Node.js Fundamentals: Web Server Without Dependencies

#34

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…

Sinatra and express brought something very important and retaught me something: value simplicity. I can't imagine how a lot of projects would look like without their influence.

Re: Node.js Fundamentals: Web Server Without Dependencies

#35
post #31

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…

> innovations like the amazing standard library Excuse me?

I would agree that the node standard library is quite good compared to many other scripting languages’. It’s nothing on the gold standard (python), but light years better than what is included with stock browser-side JS.

Re: Node.js Fundamentals: Web Server Without Dependencies

#36

Earlier quoted context omitted.

People love Rails/Django because of active records ORM. No idea if JavaScript has similar ORM

Its not as opinionated as rails/django but there's typeORM among others

TypeORM exists, but I hope you really, really like having it own your schema. Its support for migrations, rather than "uh, just let us do our thing!", is sneaky-not-great. There's no documentation, for example, for how anything in a TreeRepository actually is structured in the database, and the recommendation is "let us run the DDLs on a scratch database, you can puzzle it out from there", which should make your blood run cold.

I think a lot of the decisions in TypeORM are good, but I wouldn't trust it to own my schema under any circumstances (because now even if I'm doing things sanely I have to ask if a version bump is going to break compatibility in a way that would be "magically" fixed if I just let it chew on my schema directly).

The least-bad NodeJS ORM I have found is Objection.js, but that's a lukewarm recommendation. Its TypeScript support--which, IMO, is critical--is acceptable, but the library itself is a little cumbersome.

Re: Node.js Fundamentals: Web Server Without Dependencies

#37

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…

>Need to access the request? use `req`

Well, I don't see what's especially difficult about this?

    from flask import request

    @app.route('/login', methods=['GET', 'POST'])
    def login():
        if request.method == 'POST':
            return do_the_login()
        else:
            return show_the_login_form()
I would actually argue that this is better, since I have to type "request" only once.

Although I have to admitt, the middleware thing looks quite composable.

Re: Node.js Fundamentals: Web Server Without Dependencies

#38
post #37

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…

>Need to access the request? use `req` Well, I don't see what's especially difficult about this? from flask import request @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': return do_the_login() else: return show_the_login_form() I would actually argue that this is better, since I have to type "request" only once. Although I have to admitt, the middleware thing looks quite compos…

I'm not a huge fan of decorators since they obfuscate the state of the runtime. What exactly does the call stack look like when login gets invoked? What variables are in scope? I find it difficult to reason about.

I understand that this function will execute when the HTTP server receives a GET or POST request at `/login`. The semantics of the decorator is clear-- I don't particularly take issue with that.

But the second my assumptions about the decorator break down (e.g., I think I've defined a decorator properly, but I have not), all bets are off on how to make it function properly. It's not as simple as going to the source code for the module and see what API's I'm calling.

Re: Node.js Fundamentals: Web Server Without Dependencies

#39
post #37

Earlier quoted context omitted.

>Need to access the request? use `req` Well, I don't see what's especially difficult about this? from flask import request @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': return do_the_login() else: return show_the_login_form() I would actually argue that this is better, since I have to type "request" only once. Although I have to admitt, the middleware thing looks quite compos…

I'm not a huge fan of decorators since they obfuscate the state of the runtime. What exactly does the call stack look like when login gets invoked? What variables are in scope? I find it difficult to reason about. I understand that this function will execute when the HTTP server receives a GET or POST request at `/login`. The semantics of the decorator is clear-- I don't particularly take issue with that. But the sec…

Well, You'll be happy to know that a decorator is literally just a function that takes another function as its first argument.

    @app.route(...)
    def login():
        ...


Is literally the same thing as -

    def login():
        ...

    login = app.route(login, ...)

Hopefully that clears up the air a bit?

Re: Node.js Fundamentals: Web Server Without Dependencies

#40
post #12
post #3

Earlier quoted context omitted.

JavaScript has come a long way in recent years, but the lack of a comprehensive standard library is still absolutely mind boggling.

What are you missing from the native language + lodash?

While it's a valid point that lodash provides a lot, my point is that with any other language I've ever used, I don't need to add something like lodash.
Post reply on HN