npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

fastify-react-views

v1.0.8

Published

This is a Fastify view engine which renders React components on server. It renders static markup and does not support mounting those views on the client.

Readme

fastify-react-views

This is an Fastify view engine which renders React components on server. It renders static markup and does not support mounting those views on the client.

This is intended to be used as a replacement for existing server-side view solutions, like jade, ejs, or handlebars.

Inspired by express-react-views.

Usage

npm install fastify fastify-react-views

Add it to your app

// app.js

const app = require('fastify')();
const { engine } = require('fastify-react-views');

app.register(engine, {
   templateDir: 'views'
});

app.get('/', (_, res) => res.send('ok'));

app.get('/test', (_, res) => res.view('hello', {text: 'World'}));

app.listen(3333, () => console.info('listening...'));

The first argument of the view method is the name of the template file, the second is props which are passed to your react component.

Typescript

When using typescript you can describe the type of your props.

// app.ts

interface IHello {
   text: string;
}

app.get('/test', (_, res) => {
   res.view<IHello>('hello', {text: 'World'});
});

Nest.js

You can use it with Nest.js as well.
You need to register a plugin in your nest application.

// main.ts

import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import { engine } from 'fastify-react-views';
import { AppModule } from './app.module';

async function bootstrap()
{
   const app = await NestFactory.create<NestFastifyApplication>(
      AppModule,
      new FastifyAdapter(),
   );

   app.register(engine, {
      templateDir: 'views',
   });

   await app.listen(3333)
      .then(() => console.info(`listening...`));

   return app;
}
bootstrap();

Now you can use a Render decorator at your controllers.

// app.controller.ts

import { Controller, Get, Render } from '@nestjs/common';

interface IHello {
   text: string;
}

@Controller()
export class AppController {

   @Get()
   public index()
   {
      return 'Ok';
   }

   @Get('test')
   @Render('hello')
   public test(): IHello
   {
      return {text: 'World'};
   }
}

Views

Under the hood, Babel is used to compile your views to code compatible with your current node version, using the react and env presets by default. Only the files in your views directory (i.e. app.register(engine, {templateDir: 'views'})) will be compiled.

Your views should be node modules that export a React component. These files can have js, jsx, ts or tsx extension.

// hello.jsx
import * as React from 'react';

function Hello(props)  {
  return (
    <html>
      <head>
        <meta charSet="utf-8" />
        <title>App</title>
      </head>
      <body>
        <h2>Hello {props.text}!</h2>
      </body>
    </html>
  );
}

module.exports = Hello;

or

// hello.tsx
import * as React from 'react';
import { IHello } from 'some/path';

function Hello(props: IHello)  {
  return (
    <html>
      <head>
        <meta charSet="utf-8" />
        <title>App</title>
      </head>
      <body>
        <h2>Hello {props.text}!</h2>
      </body>
    </html>
  );
}

module.exports = Hello;

License

Licensed under MIT.