Socket
Book a DemoInstallSign in
Socket

node-server-utils

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-server-utils

Node Server Utils

latest
Source
npmnpm
Version
0.0.104
Version published
Weekly downloads
15
66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Node Server Utils

Status: Beta

Build Status

Utility functions for creating node server. Handles tracking open sockets and properly shutting down sockets when shutting down the server.

  • Cluster support for running a clustered server. See the node cluster module

Example Typescript

import { Server, STATUS_CODES } from 'http'
import { consoleLogger, createAppServer, logger, shutdownAppServer, startCluster } from '../src'

let server: Server

async function startApp() {
    server = createAppServer((req, res) => {
        logger.info({ message: STATUS_CODES[200], method: req.method, url: req.url })
        res.writeHead(200, { 'Content-Type': 'text/plain' })
        res.write('OK')
        res.end()
    })
}

async function shutdownApp() {
    shutdownAppServer(server)
}

async function main() {
    await startCluster(startApp, shutdownApp, consoleLogger)
}

void main()

Logger

The logger is setup to push log messages from the cluster workers to the master thread for logging. Register a logger for logging by either passing it into startCluster() or setLogger().

FAQs

Package last updated on 13 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts