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 🙏

© 2024 – Pkg Stats / Ryan Hefner

eproxe-express-binding

v3.0.0

Published

<p align="center"> <img src="../../images/eproxe.svg"/> </p> <h2 align="center">+</h2> <p align="center"> <img src="https://raw.githubusercontent.com/aleksandryackovlev/openapi-mock-express-middleware/master/assets/express-logo.png"/> </p>

Downloads

3

Readme

eproxe-express-binding

Install

npm i eproxe-express-binding
pnpm add eproxe-express-binding

Usage

Convetions

This exntesion relies method naming conventions to keep the syntax to a minimum

  • methods starting with get will result in GET routes, the parameters passed to the method call will be parsed from the query parameters on the request, the parameters will be human readable using JSON->URL
  • methods starting with delete will result in DELETE routes, the parameters passed to the method call will be parsed from the query parameters on the request, the parameters will be human readable using JSON->URL
  • methods starting with post will result in POST routes, the parameters passed to the method call will be parsed from the request's body
  • methods starting with put will result in PUT routes, the parameters passed to the method call will be parsed from the request's body
  • defaults to post if none of these convetions are met

Example

server.ts

import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';

import { toExpress } from 'eproxe-express-binding';
import api from './api';

const app = express();
const port = 3000;

app.use(
	cors({
		origin: 'http://localhost:5173',
	})
);

app.use(bodyParser.json());

// create routes from the api object
const routes = toExpress(api);

app.use(routes);

app.listen(port, () => {
	console.log(`Example app listening on port ${port}`);
});

see a full example here

Accessing request/response

eproxe tries to abstract most of the request/response interface from the library consumer, but sometimes we must still use it when writing more complicated code

in these scenarios we can either:

Context (Recommended)

as a way of life, i cannot reccomend enough you use context inside express, it kinda makes you wonder why it isnt like this in the first place taking the power of context and hooks known and loved by react devs into node here is a short example of accessing the request/response in our api using express context

app.ts

import { ExpressProvider } from '@sgty/kontext-express';
import api from './api';

// wrap the app with the express context
app.use(ExpressProvider());

app.use(toExpress(api));

api/index.ts

import { useExpress } from '@sgty/kontext-express';

const api = {
	doSomething() {
		const { req, res } = useExpress();

		res.setHeader('is-using-context', 'absolutely');

		return `something was done here: ${req.originalUrl}`;
	},
};

export default api;

see more about context in node and express here

Middleware

write an express middleware, we can invoke our code before, or after the original eproxe code is run