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

beansio

v1.1.33

Published

Logger for logging system events for [Beansio](https://beansio.app/)

Downloads

153

Readme

Beans (😏)

Logger for logging system events for Beansio

How to use beans to log middleware events

Remix.js Route logger Example

///init beans in the server.tsx file
import { plantBeans, remixRouteLogger,remixBeans } from 'beansio'

plantBeans('APII-KEY')
//init special remix functions

//set up sessions
const sessionStorage = createCookieSessionStorage({
  cookie: {
    name: "__session",
    httpOnly: true,
    maxAge: 0,
    path: "/",
    sameSite: "lax",
    secrets: [process.env.SESSION_SECRET || ''],
    secure: process.env.NODE_ENV === "production",
  },
});

//add middleware for remix
app.use(
    remixRouteLogger(

        async (req: any) => {
            const USER_SESSION_KEY = "userId";

            //this function sets user identifiers that can be stored on the db
            const cookie = req.headers['cookie']
            const session = await sessionStorage.getSession(cookie)
            const user =  session.get(USER_SESSION_KEY)

            return  user; ///optional customise return messages
        }
        , async (req: any) => {
            //this function lets users set custom meta data to be stored
            return {}; //set meta data
        }
    )
)   

Graphql example

import { plantBeans, graphQlLogger } from 'beansio'

plantBeans('APII-KEY')

const server = new GraphQLServer({
  schema,
  context: createContext,
  middlewares: [permissions],
})
server.express.use(

  graphQlLogger((req: any) => {
    //this function sets user identifiers that can be stored on the db
    if (!req.user) {
      return ""; //must be a string
    }
    return req.user.email || ""; ///optional customise return messages
  }, (req: any) => {
    //this function lets users set custom meta data to be stored
    return {}; //set meta data
  })
)
server.start(res => console.log(`We're live on port ${res.port}`));

Express Example

const express = require('express')
const app = express()
const port = 3100
//import beans library
import { plantBeans, routeLogger } from 'beansio'

plantBeans('APII-KEY')

//Calling the ExpressBeans function to log all 
app.use(routeLogger(  (req )=>{
  //this function sets user identifiers that can be stored on the db
 

  if ( !req.user) {
      return ""; //must be a string
  }

   return req.user.email || ""; ///optional customise return messages
} ,(req)=>{
   //this function lets users set custom meta data to be stored
   return  {}; //set meta data
}))




app.get('/', (req, res) => {
  res.send('Hello World!')
})

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

How to use beans to log Custom messages

    const event = () =>{
        ///perfom operation
        beans.logMessage('Event triggered by user ',{})
    }

How to use beans to log an error event

    const startJokeServer =   () =>{
        app.listen(port, () => {
           //////
        }).on('error', (error) => {
            beans.logError('Error starting server',{})
        });
    }

How to use beans as an error handler

    // Error fallback
    import { plantBeans, beansErrorHandler } from 'beansio'

    plantBeans('APII-KEY')
    ///
    ///
    app.use(beansErrorHandler);
    

beansio

beansio