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

@mojolicious/server-starter

v2.1.2

Published

UNIX superdaemon with support for socket activation

Downloads

946

Readme

server-starter

UNIX superdaemon with support for socket activation.

Description

This module exists to handle socket activation for TCP servers running in separate processes on UNIX. It is capable of assigning random ports to avoid race conditions when there are many services running in parallel on the same machine. As is common with large scale testing.

The superdaemon will create the listen socket and pass it to the managed process as fd=3, similar to how systemd handles socket activation. This also avoids any race conditions between spawning the managed process and sending the first request, since the listen socket is active the whole time.

import http from 'http';

const server = http.createServer((req, res) => {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World!');
});
server.listen({fd: 3});

All the web application has to do is use fd=3 as its listen socket to accept new connections from.

import ServerStarter from '@mojolicious/server-starter';
import fetch from 'node-fetch';

const server = await starter.newServer();
await server.launch('node', ['server.js']);
const url = server.url();

const res = await fetch(url);
const buffer = await res.buffer();
console.log(buffer.toString('utf8'));

await server.close();

The managed TCP server does not need to be a Node application. In fact this module was originally developed to test Mojolicious web applications written in Perl with Playwright. For more details take a look at the blog post.

import t from 'tap';
import ServerStarter from '@mojolicious/server-starter';
import {chromium} from 'playwright';

t.test('Test the WebSocket chat', async t => {
  const server = await ServerStarter.newServer();
  await server.launch('perl', ['chat.pl', 'daemon', '-l', 'http://*?fd=3']);
  const browser = await chromium.launch();
  const context = await browser.newContext();
  const page = await context.newPage();
  const url = server.url();

  await page.goto(url);
  await page.click('text=Chat');
  t.equal(page.url(), url + '/chat');
  await page.click('input[type="text"]');
  await page.fill('input[type="text"]', 'test');
  await page.click('text=Send');
  await page.click('input[type="text"]');
  await page.fill('input[type="text"]', '123');
  await page.press('input[type="text"]', 'Enter');
  const firstMessage = await page.innerText('#messages p:nth-of-type(1)');
  t.equal(firstMessage, 'test');
  const secondMessage = await page.innerText('#messages p:nth-of-type(2)');
  t.equal(secondMessage, '123');

  await context.close();
  await browser.close();
  await server.close();
});

Install

$ npm i @mojolicious/server-starter

Support

If you have any questions the documentation might not yet answer, don't hesitate to ask in the Forum, on Matrix, or IRC.