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

@zsnout/core

v1.0.13

Published

An all-in-one server, including Fastify, Socket.IO, Fastify-Static, database, and mail providers.

Downloads

5

Readme

This module creates a Fastify server with a Socket.IO server attatched. Additionally, it exports simple functions for serving directories and adding database/mail providers.

JavaScript API

server: FastifyInstance

The main Fastify server.

server.database: DatabaseProvider

The server's database provider. See interface DatabaseProvider for more information.

NOTICE: This property may not exist. To check if a database provider has been added using addProvider(), use hasProvider() or onProvider().

server.mailer: MailProvider

The server's mail provider. See interface MailProvider for more information.

NOTICE: This property may not exist. To check if a mail provider has been added using addProvider(), use hasProvider() or onProvider().

server.io: SocketIOInstance<IOEvents, IOEvents, IOServerEvents>

The server's Socket.IO instance.

listen(port: number, host?: string, backlog?: number): Promise<void>

Starts listening for connections on the server instance. Returns a promise that resolves once the server accepts connections.

  • port: number - The port to listen on.
  • host?: string - The host to listen on.
  • backlog?: number - The number of connections to backlog before refusing new connections.

addProvider<T extends keyof Providers>(type: T, provider: Providers[T]): void

This function is also added as a server instance method as server.addProvider.

Adds a database or mail provider to the server instance.

  • type: T - The type of provider to add.
  • provider: Providers[T] - The provider to add.

hasProvider(type: keyof Providers): boolean

This function is also added as a server instance method as server.hasProvider.

Checks if a provider has been added to the server instance. Returns a boolean indicating if the server has the provider.

  • type: keyof Providers - The type of provider to check for.

onProvider(type: keyof Providers): boolean

This function is also added as a server instance method as server.onProvider.

Waits for a provider to be added to the server instance. A boolean indicating if the server has the provider.

  • type: keyof Providers - The type of provider to wait for.

serveDirectory(root: string, prefix?: string): void

This function is also added as a server instance method as server.serveDirectory.

Serves a directory of static files.

  • root: string - A path to the directory containing files to send to the client.
  • prefix?: string - An optional prefix to serve files under.

TypeScript API

interface Collection<T extends Table>

An interface all database collections must implement.

Collection.find(query: Partial<T>): Promise<readonly Readonly[]>

Find documents in the collection. Returns a promise resolving to an array of documents.

  • query: Partial<T> - A filter to match documents against.

Collection.insert(...documents: T[]): Promise<void>

Inserts documents into the collection. Returns a promise resolving once the documents have been inserted.

  • ...documents: T[] - The documents to insert.

Collection.update(query: Partial<T>, data: Partial<T>): Promise<void>

Updates documents in the collection. Returns a promise resolving once the documents have been updated.

  • query: Partial<T> - A filter to match documents against.
  • data: Partial<T> - The data to update the documents with.

Collection.delete(query: Partial<T>): Promise<void>

Deletes documents from the collection. Returns a promise resolving once the documents have been deleted.

  • query: Partial<T> - A filter to match documents against.

interface Database extends StructuredDatabase

A list of collections in the main database. Used for autocomplete.

interface DatabaseProvider

The interface a database provider must implement.

DatabaseProvider.collection<T extends keyof Database>(table: T): Promise<Collection<Database[T]>>

Gets a collection from the database. Returns a promise resolving with a collection instance for the given table.

  • table: T - The name of the collection to get.

interface IOEvents

A collection of client events that can be used by the socket.io instance.

interface IOServerEvents

A collection of server events that can be used by the socket.io instance.

interface MailProvider

An interface all mail providers must implement.

interface Providers

A list of providers that can be added to the server instance.

interface Table

A type alias for a database table.

type StructuredDatabase = { [table: string]: Table }

The base structure for a database.