/vanilla-ssr

Production-ready example of a self-contained SSR server

Primary LanguageJavaScript

Vanilla SSR example (NodeJS)

This repository contains the example of a completely self-contained vanilla SSR implementation using NodeJS. This is production-ready code and it can be used as the starting point for your SSR-enabled projects.

Running the example

The example can be executed using most recent versions of NodeJS, but was specifically tested using version 18 LTS.

To run the example, use the node server.js command.

Environment variables

The PORT and HOST environment variables can be used to specify the port and host address respectively. The defaults are 8080 and 127.0.0.1 (localhost).

Static files

The SSR server in this example is completely self-contained and does not rely on additional services such as static file server or CDN to serve the static files. The static files are found in the public directory, and are cached completely in-memory when the server starts.

Dynamic HTML

The HTML generated by this server is dynamic, meaning it has data embedded inside of the markup that changes on each request. To simplify things, this data is a simple timestamp. In real-world applications, the data might come from some API or a database.

Progressive enhancement

This simple application uses progressive enhancement. This means that the basic features of the page will work without any client-side JavaScript or even without CSS. The client-side code, when available, will enhance the user experience, but it is never used for essential functionality.

Additional reading