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

next-firebase-config

v1.0.1

Published

A reusable Firebase configuration package for Next.js applications with environment variable support

Readme

Next Firebase Config

A reusable Firebase configuration package for Next.js applications with environment variable support.

Installation

npm install next-firebase-config firebase

Setup

1. Environment Variables

Create a .env.local file in your Next.js project root and add your Firebase configuration:

NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key_here
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=your_measurement_id

2. Usage

Option 1: Default Export (Automatic Initialization)

// firebase.ts
import { auth, db, storage, app } from 'next-firebase-config';

export { auth, db, storage, app };

Option 2: Manual Initialization

// firebase.ts
import { initializeFirebase } from 'next-firebase-config';

const { auth, db, storage, app } = initializeFirebase();

export { auth, db, storage, app };

Option 3: Custom Configuration

// firebase.ts
import { initializeFirebase, FirebaseConfig } from 'next-firebase-config';

const customConfig: FirebaseConfig = {
  apiKey: "your-api-key",
  authDomain: "your-domain.firebaseapp.com",
  projectId: "your-project-id",
  storageBucket: "your-bucket.appspot.com",
  messagingSenderId: "your-sender-id",
  appId: "your-app-id",
  measurementId: "your-measurement-id"
};

const { auth, db, storage, app } = initializeFirebase(customConfig);

export { auth, db, storage, app };

Usage in Components

// components/LoginForm.tsx
import { auth } from '../firebase';
import { signInWithEmailAndPassword } from 'firebase/auth';

export function LoginForm() {
  const handleLogin = async (email: string, password: string) => {
    try {
      await signInWithEmailAndPassword(auth, email, password);
    } catch (error) {
      console.error('Login failed:', error);
    }
  };

  // ... rest of component
}
// pages/api/users.ts
import { db } from '../../firebase';
import { collection, getDocs } from 'firebase/firestore';

export default async function handler(req, res) {
  try {
    const usersSnapshot = await getDocs(collection(db, 'users'));
    const users = usersSnapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
    res.status(200).json(users);
  } catch (error) {
    res.status(500).json({ error: 'Failed to fetch users' });
  }
}

API Reference

initializeFirebase(config?: FirebaseConfig): FirebaseServices

Initializes Firebase with the provided configuration or environment variables.

Parameters:

  • config (optional): Firebase configuration object

Returns:

  • Object containing { app, auth, db, storage }

createConfigFromEnv(): FirebaseConfig

Creates a Firebase configuration object from environment variables.

FirebaseConfig

interface FirebaseConfig {
  apiKey: string;
  authDomain: string;
  projectId: string;
  storageBucket: string;
  messagingSenderId: string;
  appId: string;
  measurementId?: string;
}

FirebaseServices

interface FirebaseServices {
  app: FirebaseApp;
  auth: Auth;
  db: Firestore;
  storage: FirebaseStorage;
}

Error Handling

The package validates required configuration fields and throws descriptive errors for missing values:

try {
  const firebase = initializeFirebase();
} catch (error) {
  console.error('Firebase initialization failed:', error.message);
}

TypeScript Support

This package is written in TypeScript and includes full type definitions. No additional @types packages are needed.

License

MIT