[HN Gopher] Show HN: Citizen - A Node.js web app framework for f...
___________________________________________________________________
Show HN: Citizen - A Node.js web app framework for fans of classic
app servers
Citizen is a web application framework I started building years ago
when I was first learning Node. I've added features and improved
stability/performance continuously and finally decided it was
worthy of 1.0 status. I think it might appeal to devs like me (old
guys) who came up on app servers like ColdFusion, .NET, PHP, etc.
and prefer the server do the heavy lifting. It doesn't dictate
anything about your front end, and instead tries to be as flexible
as possible in providing whatever output the client might need,
whether it's a single fully-rendered HTML view, partials, JSON, or
plain text. Only 2 direct dependencies for terminal commands
(commander) and file watching (chokidar). Built-in functionality
includes zero-configuration server-side routing, session
management, key/value store (cache rendered views, controller
actions, objects, and static files), simple directives for managing
cookies, sessions, redirects, and caches, and more. It's been in
continuous use on at least one site that receives hundreds of
thousands of page views per month, running months at a time without
the process crashing. Fairly stable. Appreciate any
comments/feedback/contributions.
Author : jaysylvester
Score : 39 points
Date : 2024-10-16 18:48 UTC (4 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| mannyv wrote:
| Your docs are great!
| jaysylvester wrote:
| Thank you! I try to be thorough. Getting to be a bit much for a
| readme though, probably deserves its own site.
| williamdclt wrote:
| Congrats! Seems like a considerable project, I appreciate the
| low-dependency approach.
|
| > hundreds of thousands of page views per month
|
| I'm not sure I'd include that as any sort of perf/stability
| argument. Even only assuming traffic is only clustered over 8h of
| the day, it's 0.1 to 1req/sec. The worst web framework out there
| in any language probably could handle that
| jaysylvester wrote:
| That's a fair observation. I only include it because the Node
| way of doing things seems to be "just let the process crash and
| restart it", and that's been a tough concept for me to accept.
| I'm particularly proud of error handling in citizen and want it
| to be as much like an old-school app server as possible.
|
| I still use pm2 on the aforementioned site just in case though,
| and maybe seeing that extended process uptime is just a feel-
| good exercise, but still worth mentioning.
|
| I've been meaning to do real performance testing and keep
| pushing it off because it's been adequate for my needs.
| korkybuchek wrote:
| Are there any tests for this library? And it looks like you don't
| support Typescript, is that planned?
| jaysylvester wrote:
| No tests yet, that's been on my list since the beginning and I
| now have the incentive to work on them:
|
| https://github.com/jaysylvester/citizen/issues/24
|
| I don't use TypeScript myself, but based on what I know, I
| don't think it would be difficult to add support. I just opened
| an issue to track it:
|
| https://github.com/jaysylvester/citizen/issues/131
| mrcwinn wrote:
| "No tests yet, been on my list." This truly is fitting within
| classic software norms. Bravo.
| jaysylvester wrote:
| At least I stopped deploying site updates via FTP.
| accrual wrote:
| This is really cool! I cut my web development teeth on LAMP
| (Linux Apache MySQL PHP) and MVC was my favorite pattern to
| implement. I appreciate how it breaks out each concern into its
| own folder or files and gives the developer control over the
| details like session management. For small projects I still find
| it fun and comfortable to write web apps this way.
| usbsea wrote:
| What does "server do the heavy lifting" mean here - and is this
| much different to a Rails or Django type of thing? I know in
| Node-land there are less kitchen-sink options like this though.
|
| The storage and k/v looks interesting. Django is pretty pluggable
| in that regard. Choose sqlite and a local redis and I think you
| probably have the same thing. But you do need to make choices and
| read docs to get there.
| jaysylvester wrote:
| It mostly means keeping routing/rendering/etc. on the server
| rather than client. My preference has always been to let the
| server render the initial request in full (feed the client an
| entire HTML document) and then update on the client side as
| necessary (which could be data via JSON or chunks of HTML,
| whichever makes sense) with progressive enhancement and minimal
| JS as the goal.
|
| You can of course build an API with citizen that only returns
| JSON responses and do all the rendering on the client if you
| like. It's meant to be flexible that way. Basically, the
| client-side stuff is completely up to you. I've toyed with the
| idea of building a client-side companion library that wires
| everything up so server citizen and client citizen talk to each
| other and do what I described in the previous paragraph
| automagically.
|
| I started citizen a decade ago, so many options available today
| were either non-existent or in their infancy then. I haven't
| performed a competitive analysis to compare features with other
| frameworks. You nailed it though on the lack of kitchen-sink-
| type frameworks in Node (especially 10 years ago), which is why
| I built citizen. And I didn't like the idea of depending on so
| many third-party packages.
| danpalmer wrote:
| I grew up on Django and have separately seen and contributed to
| numerous Flask codebases. It has become abundantly clear to me
| that web apps of any real size that use the library approach
| (rather than framework) typically end up with a poorly documented
| internal-only framework anyway, and that plugging together
| libraries has a significant cost. In my experience this is
| significantly more of an issue in the JS/TS/Node/etc ecosystem.
|
| My rule of thumb is to look at the feature list for a web
| framework (Django, Rails, Citizen, etc) - sessions, caching, ORM,
| rendering, routing, auth, admin, static files, APIs,
| serialisation, etc etc - and if you need 3 or more, just use a
| framework that has them all properly integrated.
|
| Example, you're sticking an internal API on your ML model, you
| need one or two endpoints, and to return some JSON. Just use
| Flask/FastAPI or whatever the equivalent in your ecosystem is.
|
| Alternatively, you're building a user-facing website, you need
| routing to endpoints, auth, sessions, and a database. Just use a
| big framework. You'll likely add more of those cross cutting
| concerns in the future anyway, and having them all work together
| rather than gluing libraries together will save a ton of time.
|
| Citizen is the first convincing framework I've seen for this
| approach from the Node ecosystem. Congrats on the 1.0!
___________________________________________________________________
(page generated 2024-10-16 23:00 UTC)