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

@backan/server

v0.0.25

Published

Build the Backan server with zero config.

Downloads

38

Readme

BACKAN - Server

HEADER

Web About Us Donate Github Twitter Instagram Medium

License Version

BACKAN Create endpoints with type validations and OpenApi documentation, safely and quickly.

This package contains BACKAN Server library

Build the backan server with zero config.

🔑 Installation

npm install @backan/server 
pnpm i @backan/server
yarn add @backan/server 

NPM Version

📈 usage

import {server} from '@backan/server'
import {App} from 'backan' 

// create backan app
const app = new App( {
	version     : '1.0.0',
	title       : 'BACKAN sample application',
})

// create server for backan
server({ app })

⚙️ Configuration

The backan server comes ready to use without any configuration, but this does not mean that we can configure certain aspects of the server if we want.

Here is a list of the available options.

/**
 * Options for server function. 
 * 
 */
type ServerOpts = {
	/**
	 * The `backan` app instance. 
	 *
	 */
	app: App<Env>,
	/**
	 * The port to start the server on.
	 *
	 * @default 80
	 */
	port?: number
	/**
	 * The hostname to bind the server.
	 *
	 * @default 'localhost'
	 */
	hostname?: string
	/**
	 * The protocol to use. Defaults to 'http' unless the port is 443.
	 * Note: This will be available soon. Currently this does not modify the port, the service is always on http.
	 *
	 * @default 'http'
	 */
	protocol?: 'http' | 'https',
	/**
	 * If true, automatically find an available port if the specified port is in use.
	 *
	 * @default false
	 */
	autoPort?: boolean
	/**
	 * If true, You can pass the parameters {port,autoPort,hostname,protocol} as flags. Example: ---port=1312 --autoPort.
	 *
	 * @default false
	 */
	allowFlags?: boolean
	/**
	 * Optional callback invoked when the server starts successfully.
	 */
	onSuccess?: ( info: ServerInfo ) => Promise<void>
	/**
	 * Optional callback invoked when an error occurs.
	 */
	onError?: ( opts: {
		/**
		 * Server error id.
		 */
		id: ServerError, 
		/**
		 * Error catched in process.
		 */
		error: unknown, 
		/**
		 * Data info of server.  
		 */
		data: ServerInfo
	} ) => Promise<void>
	onExit?: ( opts: {
		/**
		 * Data info of server.  
		 */
		data: ServerInfo
	} ) => Promise<void>
}

/**
 * Data info of server.
 *
 */
type ServerInfo = {
	/**
	 * The server hostname.
	 *
	 */
	hostname: string
	/**
	 * The server port.
	 *
	 */
	port: number
	/**
	 * The server protocol.
	 *
	 */
	protocol: string
	/**
	 * The server url: `${protocol}://${hostname}:${port}`.
	 *
	 */
	url: string
}

💡 Examples

Zero config

/**
 * Start a server with zero config for BACKAN
 *
 * @see https://backan.pigeonposse.com/guide/server
 */

import { server } from '@backan/server'
import app        from './app.js' // your backan app

await server({ app })

Fully customized

/**
 * Start a fully customized server for BACKAN
 *
 * @see https://backan.pigeonposse.com/guide/server
 */

import { server } from '@backan/server'
import app        from './app.js' // your backan app

await server( {
	app        : app,
	hostname   : 'localhost',
	protocol   : 'http',
	port       : 1312,
	autoPort   : true,
	allowFlags : true,
	onError    : async ( { id, error } ) => {
		
		if( id === 'UNEXPECTED' ) console.error( '🐦💔 UNEXPECTED Error' )
		else if( id === 'PORTS-NOT-AVAILABLE' ) console.error( '🐦💥🚢 No ports availables' )
		else if( id === 'PORT-NOT-AVAILABLE' ) console.error( '🐦💥🚢 No port available' )
		else if( id === 'HOSTNAME-NOT-VALID' ) console.error( '🐦💥🌐 Hostname not available' )
		console.error( '\n',error )
	
	},
	onSuccess : async ( info ) => {

		console.info( '🐦✅ Server info', info )
	
	},
	onExit : async () => {

		console.warn( '\n\n🐦👋 Fly High Pigeon\n' )
	
	},
} )

More from Backan

👨‍💻 Development

BACKAN is an open-source project and its development is open to anyone who wants to participate.

Issues Pull requests Read more

☕ Donate

Help us to develop more interesting things.

Donate

📜 License

This software is licensed with GPL-3.0.

Read more

🐦 About us

PigeonPosse is a ✨ code development collective ✨ focused on creating practical and interesting tools that help developers and users enjoy a more agile and comfortable experience. Our projects cover various programming sectors and we do not have a thematic limitation in terms of projects.

More

Collaborators

| | Name | Role | GitHub | | ---------------------------------------------------------------------------------- | ----------- | ------------ | ---------------------------------------------- | | | Angelo | Author & Development | @Angelo | | | PigeonPosse | Collective | @PigeonPosse |

Web About Us Donate Github Twitter Instagram Medium