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.

I made a new TypeScript runtime on Node.js

1 pointsby sbjsalmost 2 years ago
Honestly I was tired of writing traditional server-side apps and modern client-side apps. Both felt like they were going in the wrong direction.<p>With server-side frameworks, there were so many things that felt unnatural. Why should I have to look up items in a database every single time a user hits a route? Why should I allow every possible string combination in &#x2F;product&#x2F;:id or &#x2F;post&#x2F;:slug.html when I know ahead of time that there&#x27;s only a few dozen? Why should I write in a template language that&#x27;s mostly copying JavaScript&#x27;s own features?<p>For client-side the difficulty was that I didn&#x27;t want to write a heavily dynamic site. In terms of UI, a traditional server would have worked just fine, as you just navigate from page to page. So why should I write it entirely in the client?<p>I get the reasoning. For one thing, this lightens the load of servers, allowing them to serve more clients at once. But at what cost? Serving multi-megabyte client files in place of multiple requests with much smaller payloads doesn&#x27;t make a lot of sense.<p>So I wrote a ton of stuff, and only started open sourcing some of it recently, namely Principia (https:&#x2F;&#x2F;github.com&#x2F;sdegutis&#x2F;principia).<p>The overall approach I took was to create a server-side framework where as much as humanly possible was precomputed and pre-rendered. The framework is built around this by design.<p>For instance, when the site loads, it creates every route handler as a separate function and places them in a giant map with every known URL. This makes sitemaps super easy and fast, it avoids a database lookup for any request, and it makes for extremely quick HTTP request handlers.<p>And it turns out JSX is very easily precomputed at runtime if you just create a thin runtime on top of Node.js that compiles TypeScript to JavaScrip and runs it inside a virtual Node module. Which in turn also makes hot-reloading extremely natural to implement.<p>Overall I&#x27;ve written 3 or 4 websites using this, and I&#x27;m convinced it&#x27;s a better than express.js for many types of sites.

no comments

no comments