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 🙏

© 2025 – Pkg Stats / Ryan Hefner

egx

v0.0.6

Published

Express got Htmx and JSX

Downloads

17

Readme

Egx

An ExpressJS Got Htmx and JSX.

ExpressJS is a Fast, unopinionated, minimalist web framework.

Htmx gives you access to AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext.

JSX it's just JavaScript XML. JSX makes it easier to write markup HTML.

Features

  • Hooks support (useRequest, useResponse, useBody, useParams, useQuery, etc.).
  • Helmet support.
  • AsyncComponent support.
  • CleanupComponent support.

Install

Starter Template

npx degit herudi/egx/starter my-app
cd my-app
npm install

// run dev
npm run dev

// build
npm run build

// run prod
npm run start

Install Manually

npm i egx

Basic Usage

/** @jsx h */
/** @jsxFrag h.Fragment */

import express from "express";
import { egx, h, Helmet } from "egx";

const app = express();

app.use(egx());

app.get("/", (req, res) => {
  res.egx(
    <div>
      <Helmet>
        <title>Welcome Home</title>
      </Helmet>
      <button hx-post="/clicked" hx-swap="outerHTML">Click Me</button>
    </div>,
  );
});

app.post("/clicked", (req, res) => {
  res.egx(<h1>It's Me</h1>);
});

// handling promise
app.get("/pet", async (req, res, next) => {
  try {
    await res.egx(<h1>Cat</h1>);
  } catch (err) {
    next(err);
  }
});

app.listen(3000, () => {
  console.log("> Running on port 3000");
});

Using Hooks

useRequest

const Foo = () => {
  const { url } = useRequest();
  return <h1>{url}</h1>;
};

useResponse

const Foo = () => {
  const res = useResponse();
  res.set("my-header", "value");
  return <h1>hello</h1>;
};

useParams

type User = { name: string };

const Foo = () => {
  const { name } = useParams<User>();
  return <h1>{name}</h1>;
};

app.get("/user/:name", (req, res) => {
  res.egx(<Foo />);
});

useQuery

type User = { name: string };

const Foo = () => {
  const { name } = useQuery<User>();
  return <h1>{name}</h1>;
};

app.get("/user", (req, res) => {
  res.egx(<Foo />);
});

// GET /user?name=john

useBody

type User = { name: string };

const UserPost = async () => {
  const user = useBody<User>();
  // example save to db
  await db.user.save(user);

  return <h1>{user.name}</h1>;
};

app.post("/user", (req, res) => {
  res.egx(<UserPost />);
});

Using Cleanup Component

A cleanup component for any custom send. for example: json/redirect.

Example Sign and redirect

const Sign = async () => {
  const req = useRequest();
  const res = useResponse();

  const token = await getToken(req.body);

  if (token) {
    // use cleanup to redirect
    return () => {
      res.cookie("user", token).redirect("/admin");
    };
  }
  return <SignPost message="login failure" />;
};

Example Auth and NextFunction

const Auth: FC = (props) => {
  const req = useRequest();
  const next = useNext();

  if (req.isLogin === false) {
    // use cleanup to next function
    return () => {
      next(new Error("user not found"));
    };
  }

  return props.children;
};

app.get("/", (req, res) => {
  res.egx(
    <Auth>
      <Home />
    </Auth>,
  );
});

License

MIT