TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Node.js Fundamentals: Web Server Without Dependencies

192 点作者 bloomca超过 6 年前

11 条评论

jpalomaki超过 6 年前
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 未加载
mirekrusin超过 6 年前
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 未加载
Vanit超过 6 年前
I still write little http servlets like this sometimes, especially for something like gluing IoT services together.
lioeters超过 6 年前
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>
brod超过 6 年前
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>
gyrgtyn超过 6 年前
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>
tofflos超过 6 年前
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>.
craftoman超过 6 年前
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 未加载
partycoder超过 6 年前
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
nurettin超过 6 年前
you can do the same (except loading certs) with python3 these days thanks to asyncio.
keketi超过 6 年前
But can it left pad a string?
评论 #18749161 未加载
评论 #18749084 未加载
评论 #18749029 未加载
评论 #18749201 未加载