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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@batoanng/frontend-server

v2.3.0

Published

[![install size](https://packagephobia.com/badge?p=%40batoanng%2Ffrontend-server)](https://packagephobia.com/result?p=%40batoanng%2Ffrontend-server)

Downloads

60

Readme

Frontend Server

install size


Does most of the heavy-lifting for front-end server.js applications. Proxies all requests to the API to a target server, catering for CORS, CSP, and HSTS. Optionally forwards payment completion responses to the Forms API.

Usage

npm install @batoanng/frontend-server # or yarn, pnpm

You can configure your own front-end server using code something as follows:

import path from 'path';
import dotenv from 'dotenv';
import { fileURLToPath } from 'url';
import { buildServer } from '@batoanng/frontend-server';

// load env
const dirname = path.dirname(fileURLToPath(import.meta.url));
const clientBuildPath = path.join(dirname, '../build');

const env = process.env.NODE_ENV?.toLowerCase() ?? null;

if (env === null) {
  console.log('Warning: process.env.NODE_ENV is not set, using .env as the default');
}

const envFile = env === null 
  ? path.join(dirname, '.env') 
  : path.join(dirname, '.env.' + env);

dotenv.config({ path: envFile });

const { server } = buildServer({
  targetServerUrl: process.env.APP_API_TARGET_SERVER,
  nodeEnv: env,
  indexOptions: {
    filename: 'index.html',
    globalClientEnvVariableName: 'process.env',
  },
  appPrefix: process.env.APP_URL_PREFIX,
  clientBuildPath: clientBuildPath,
  cspOptions: {
    services: [
      'google-analytics',
      'google-translate',
      'newrelic',
      'hotjar',
      'full-story',
      'google-fonts',
    ],
    connectSrcElements: [
      'https://*.your-domain.com'
    ],
    scriptSrcElements: [
      "'sha256-eVzrNv8f3FKjQhflSMC3+yFtNdThPi+cT+245HpcDV0='", // non-english inline scripts for Google Translate
      "'sha256-yjCTgtivmXYtWQuObDl8BjTbkgRha9Pk2lo0RDPrymA='", // newRelic.tsx
    ]
  },
  corsOptions: {
    allowedOrigins: [process.env.REACT_APP_BASE_URL, 'http://127.0.0.1:3000']
  },
  newRelic: {
    applicationId: 'NR-123...'
  },
  configure: (server: Express, proxyBuilder: BuildServerProxyBuilder) => {
    // Additional configuration required for Express
  },
});

const port = process.env.PORT ?? 3000;

server.listen(port, () => {
  console.log(`App Server is running on port ${port}`);
});

CSP

The CSP can be modified by passing in:

  • services - the list of "known" services to include across all the CSP directives
  • *Elements - additional elements that will be added to the relevant CSP directive

Automatic client-side env variable injection

Client side variables loaded from the client's .env files will automatically be injected into the HTML page and made available before the application scripts are executed. By default, the injection point for these variables replicates the legacy webpack method by using window.process.env, but this can be customized using the indexOptions.globalClientEnvVariableName parameter.

The relevant SHA for the script will also be generated and added to the site's CSP settings.

createClientEnvFilesPlugin

This plugin can be included in the plugins list for vite to automatically create/copy the correct client .env files to the build folder, which can then be picked up by frontend server at runtime, and injected into the index.html file.

.env files can be globbed (i.e. merged) with a "common .env file by passing true to the plugin configuration. Alternatively, the glob setting may be passed as:

  • string[] - An array of filenames to glob, overriding earlier files with later files, before finally including the specific file based on the environment name.
  • (validEnvironment: string) => string[] - Allows full manual control. The glob will combine all the files named in the resulting array. The resulting file paths should be relative to the envPath setting.