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 🙏

© 2025 – Pkg Stats / Ryan Hefner

express-auto-frontend

v1.0.2

Published

Effortlessly connect and serve any modern frontend (React, Vue, Angular, Svelte) with your Express backend in development and production.

Readme

# express-auto-frontend

[![npm version](https://badge.fury.io/js/express-auto-frontend.svg)](https://badge.fury.io/js/express-auto-frontend)

Effortlessly connect and serve any modern frontend (React, Vue, Angular, Svelte) with your Express backend in development and production.

---

## Why Express Auto Frontend?

Developers often face repetitive tasks when connecting a frontend and backend:

- Manually setting up proxies for dev servers
- Handling CORS issues
- Remembering frontend build paths
- Writing separate deployment scripts  

`express-auto-frontend` **automates all of this**, giving you a seamless full-stack development experience.

---

## Advantages

- **Automatic Detection:** Detects your frontend framework (React, Vue, Angular, Svelte, Nuxt, or static files).  
- **Zero-Config Dev Proxy:** Automatically proxies API requests to your backend during development.  
- **Production Ready:** Serves optimized static builds with SPA routing support.  
- **Framework Agnostic:** Works with all major modern frontends and static sites.  
- **Unified Development Workflow:** One server to run, one URL to access, no CORS headaches.  

---

## Use Case Scenario

Imagine you have a React frontend built with Vite and an Express API backend. Traditionally, you'd:

1. Start your Express server on port 3000
2. Start the React dev server on port 5173
3. Configure a proxy in `vite.config.js` to send API calls to Express
4. Deal with CORS issues in production builds  

With `express-auto-frontend`:

1. You just call `include(app, '../frontend')` in your Express server
2. The frontend is automatically detected
3. Dev server starts and proxies are automatically configured
4. Production build is served from Express  
All of this **without additional configuration**.

---

## Installation

```bash
npm install express-auto-frontend

Quick Start

server.js

const express = require('express');
const include = require('express-auto-frontend');

const app = express();
const PORT = 3001;

// API routes
app.get('/api/message', (req, res) => {
    res.json({ message: 'Hello from the backend!' });
});

// Automatically include frontend (detects React, Vue, Angular, Svelte, or static)
include(app, '../frontend');

app.listen(PORT, () => {
    console.log(`Server running on http://localhost:${PORT}`);
});

What happens now:

  • Dev: Frontend dev server runs automatically, /api/* routes go to Express, everything else goes to frontend dev server.
  • Prod: Static build served automatically with SPA routing fallback.

How It Works

Development Mode

  • Express runs on your chosen backend port (e.g., 3001).
  • Frontend dev server runs on its default port (e.g., Vite: 5173, Vue CLI: 8080).
  • API requests (/api/*) are proxied to Express.
  • Frontend requests (/*) are proxied to the frontend dev server.
  • Provides one unified URL during development.

Production Mode

  • Frontend npm run build outputs static files (dist/build).
  • Express serves static files automatically.
  • SPA routing is supported by fallback to index.html.

Configuration

Optional config object as the third argument:

include(app, '../frontend', {
    backendPort: 3001, // Required for proxying
    devPort: 8080,     // Override frontend dev server port
    buildDir: 'build', // Override build directory
    devScript: 'start' // Override npm dev script
});

Default Framework Configurations

| Framework | Dev Port | Build Dir | Dev Script | | ------------ | -------- | ----------------- | ---------- | | React (Vite) | 5173 | dist | dev | | Vue (CLI) | 8080 | dist | serve | | Angular | 4200 | dist/project-name | start | | SvelteKit | 5173 | build | dev |


Supported Frontends

  • ✅ React (Vite or CRA)
  • ✅ Vue (Vue CLI or Nuxt)
  • ✅ Angular
  • ✅ Svelte / SvelteKit
  • ✅ Static HTML or Pug

License

MIT



## **🔧 Development Workflow**

┌──────────────────────────┐ │ Browser (User) │ └───────────────┬──────────┘ │ Frontend Requests (/, /assets, etc.) │ ▼ ┌──────────────────────┐ │ Frontend Dev Server │ │ (React/Vue/Angular/ │ │ Svelte, etc.) │ └──────────┬───────────┘ │ Hot Reload / HMR │ ─────────────────┼──────────────────────────── │ API Requests (/api/*) │ ▼ ┌──────────────────────┐ │ Express Backend │ │ (API + Proxying) │ └──────────────────────┘


### **How it works in dev:**

* Browser requests **frontend UI** → sent to the **frontend dev server** (Vite/Webpack/Angular CLI).
* Browser requests **`/api/...`** → Express backend handles them.
* Express proxies UI requests to frontend dev server automatically.
* Full hot-reloading & unified origin → **no CORS needed**.

---

## **🚀 Production Workflow**

┌──────────────────────────┐ │ Browser (User) │ └───────────────┬──────────┘ │ All UI Requests (/, /js/, /css/) │ ▼ ┌──────────────────────┐ │ Express Serves Built │ │ Frontend (dist/ │ │ build/ production) │ └──────────┬───────────┘ │ SPA Fallback (index.html) ─────────────────┼──────────────────────────── │ API Requests (/api/*) │ ▼ ┌──────────────────────┐ │ Express Backend │ │ (API Only) │ └──────────────────────┘


### **How it works in production:**

* Browser requests the UI → Express serves files from `dist` / `build`.
* Client-side routing works using **index.html fallback**.
* `/api/*` is handled normally by Express.
* No dev server is running.

---

## **✨ Combined Architecture Overview**
      ┌─────────────────────────┐
      │   express-auto-frontend │
      │       (Middleware)      │
      └───────────┬────────────┘
                  │ Auto-detects framework
  ┌───────────────┼────────────────┬─────────────────────┐
  ▼               ▼                ▼                     ▼

React Project Vue Project Angular Project Svelte/SvelteKit (Vite/CRA) (Vue CLI/Nuxt) (ng CLI) (Kit)

             ┌─────────────────────────────┐
             │   Development Mode          │
             │  - Runs Dev Server         │
             │  - Proxies automatically    │
             └───────────────┬─────────────┘
                             │
                             ▼
                      Unified Server
                 http://localhost:<backendPort>
             ┌──────────────────────────────┐
             │      Production Mode         │
             │   - Serves static build      │
             │   - Handles SPA fallback     │
             └──────────────────────────────┘