TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Node.js Fundamentals: Web Server Without Dependencies

192 pointsby bloomcaover 6 years ago

11 comments

jpalomakiover 6 years ago
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.
评论 #18750799 未加载
mirekrusinover 6 years ago
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.
评论 #18751875 未加载
评论 #18752093 未加载
Vanitover 6 years ago
I still write little http servlets like this sometimes, especially for something like gluing IoT services together.
lioetersover 6 years ago
Great article. Anyone working with Node.js should be familiar with these fundamentals. It also demonstrates the simplicity (and dare I say &quot;elegance&quot;, though that&#x27;s subjective..) of Node.js and its concepts.<p>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.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;zeit&#x2F;micro" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;zeit&#x2F;micro</a>
brodover 6 years ago
There are <i>a lot</i> of gotcha&#x27;s when rolling your own web server based on the http and https packages and I think the conclusion of the article could have gone further in addressing what they are and in what context they might matter. I recently wrote a little zero-dependency NodeJs http&#x2F;s server[1] with an equally dumb router for some dev tools which could benefit from a simple, promise based api, for most other use cases I&#x27;d just pull in express or something more mature.<p>[1]<a href="https:&#x2F;&#x2F;github.com&#x2F;8eecf0d2&#x2F;decade" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;8eecf0d2&#x2F;decade</a>
gyrgtynover 6 years ago
Love this. There was this project along the same lines, from the olden days of node:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;Raynos&#x2F;http-framework" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Raynos&#x2F;http-framework</a>
tofflosover 6 years ago
It&#x27;s nice to get away from frameworks from time to time. If anyone is interested in something similar written in Java I recently created a couple of examples based on Undertow. They are available at <a href="https:&#x2F;&#x2F;github.com&#x2F;tofflos&#x2F;undertow-examples" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tofflos&#x2F;undertow-examples</a>.
craftomanover 6 years ago
Performance is also a major advantage. Express is extremely slow compared to a basic &quot;native&quot; API without dependencies. If you check out the results in numbers, you&#x27;ll be amazed.
评论 #18751376 未加载
评论 #18751502 未加载
评论 #18751894 未加载
partycoderover 6 years ago
The crimes of these kinds tutorials:<p>- Downplaying the role of error handling<p>- Treating the subjects they cover as a black box<p>- Not warning that the code examples are not suitable for production
nurettinover 6 years ago
you can do the same (except loading certs) with python3 these days thanks to asyncio.
keketiover 6 years ago
But can it left pad a string?
评论 #18749161 未加载
评论 #18749084 未加载
评论 #18749029 未加载
评论 #18749201 未加载