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

create-next-app-trpc

v1.2.5

Published

A package for quickly creating Latest Next.js projects with tRPC and React Query

Downloads

45

Readme

create-next-app-trpc

Create Next.js projects seamlessly with tRPC and React Query using create-next-app-trpc. tRPC allows for type-safe API routes without schema or generation, and React Query is a powerful tool for managing server state in React applications. This package streamlines setting up a Next.js project with these advanced technologies, simplifying the initial configuration and saving valuable development time.

Introduction

tRPC and React Query enhance Next.js applications by providing efficient data fetching and state management capabilities. With create-next-app-trpc, you can kickstart your project with a pre-configured setup, focusing on building your application right away.

Prerequisites

To use this package, you'll first need to have Node.js installed on your system. If you don't have Node.js installed, you can download it from the official Node.js website.

Installation

Once Node.js is installed, you can install the create-next-app-trpc package using npm (Node Package Manager). Run the following command in your terminal:

npm install -g create-next-app-trpc

This will install the package globally on your system, allowing you to use it to create new Next.js projects with tRPC and React Query.

Usage

After installing the package, you can create a new Next.js project by running:

npx create-next-app-trpc

This command will create a new Next.js project and set up the necessary configurations for tRPC and React Query.

Prisma Support

create-next-app-trpc now includes optional support for Prisma, an open-source database toolkit, making your project ready for deployment with efficient and time-saving features. When you opt for Prisma, your project will be equipped with the following:

  • Prisma Seed: Prisma's seeding functionality is added for easy database setup. This is reflected in your package.json file under the Prisma configuration as follows:

    "prisma": {
      "seed": "ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts"
    }

    This configuration ensures that the prisma/seed.js script is executed to seed your database, providing a convenient way to populate your database with initial data.

  • Automatic Prisma Client Generation: In your package.json, the postinstall script is configured as "postinstall": "prisma generate". This ensures that the Prisma client is automatically generated after installation, simplifying your deployment process.

  • .gitignore File Automation: When Prisma is added, create-next-app-trpc automatically updates the .gitignore file to include .env, ensuring that your environment variables are not exposed in version control. This helps maintain the security and integrity of your application.

To include Prisma in your project setup, simply select 'Yes' when prompted during the creation process. This will automatically configure Prisma in your new Next.js project, saving you the time and effort of manual setup.

Features

create-next-app-trpc sets up a Next.js project with the following default features:

  • TypeScript Support (--ts): Strongly typed JavaScript for better developer experience.
  • src/ Directory Structure (--src-dir): Organized project structure with all source files in the src/ directory.
  • App Router Configuration (--app): Pre-configured router setup for immediate use.
  • Import Aliases (--import-alias): Simplify imports with the default alias "@/*" for cleaner code.

Project Structure

map -> .
├── prisma  # <-- if prisma is added
│   ├── migrations # <-- if prisma is added
│   │   └── [...]
│   ├── schema.prisma # <-- if prisma is added
│   ├── seed.ts # <-- if prisma is added
│   └── [...]
├── src
│   ├── app
│   │   ├── _context # <-- context (optional) (if next-auth is added)
│   │   │   └── AuthProvider.tsx # <-- authentication provider (if next-auth is added)
│   │   ├── _trpc  # <-- add withTRPC()-HOC here
│   │   │   └── client.ts  # <-- tRPC client
│   │   │   └── TrpcProvider.tsx  # <-- tRPC provider
│   │   │   └── serverClient.ts  # <-- tRPC server client
│   │   ├── _stores  # <-- if zustand is added
│   │   │   └── useStore.ts  # <-- zustand store
│   │   ├── api
│   │   │   ├── trpc
│   │   │   │   └── [trpc]
│   │   │   │       └── route.ts  # <-- tRPC HTTP handler
│   │   │   └── auth
│   │   │       └── [...nextauth]  # <-- if next-auth is added
│   │   │           └── options.ts # <-- next-auth options if next-auth is added
│   │   │           └── route.ts  # <-- next-auth HTTP handler if next-auth is added
│   │   ├── dashboard # <-- dashboard page (optional if next-auth is added)
│   │   │   └── [...]
│   │   └── [...]
│   ├── lib # <-- utility functions
│   │   ├── prisma.ts  # <-- prisma client (if prisma is added)
│   │   ├── models.ts  # <-- zod models (if zod is added)
│   │   ├── types.ts  # <-- types (if zod is added)
│   │   └── [...]
│   ├── server # <-- server-side code
│   │   ├── routers # <-- routers
│   │   │   ├── user.ts  # <-- sub routers (optional)
│   │   │   ├── post.ts  # <-- sub routers (optional)
│   │   │   └── [...]
│   │   ├── context.ts  # <-- context (optional if next-auth is added)
│   │   ├── index.ts  # <-- main router
│   │   └── trpc.ts      # <-- procedure helpers
│   ├── middleware.ts  # <-- middleware if next-auth is added
│   └── [...]
├── .env # <-- environment variables (if prisma or next-auth is added) automatic added to .gitignore
├── next-auth.d.ts  # <-- next-auth config if next-auth is added
└── [...]

What's Included?

The package will set up a new Next.js project with the following packages pre-installed:

  • @trpc/client
  • @trpc/server
  • @trpc/react-query
  • @tanstack/react-query
  • decimal.js
  • superjson

In addition to these, create-next-app-trpc also offers optional support for:

  • Prisma: If opted, adds prisma and @prisma/client for robust database management. Additionally, if Prisma is added, it will also include bcrypt and @types/bcrypt to simplify the process of encrypting passwords for enhanced security.
  • Zod: If chosen, includes zod for TypeScript-first schema validation.
  • React-Hook-Form: If selected, integrates react-hook-form, @hookform/resolvers for efficient form handling in React applications.
  • Next-Auth: If opted, adds next-auth for authentication and authorization in Next.js applications.
  • Zustand: If selected, includes zustand for state management in React applications.

These optional integrations can be added during the setup process, enhancing your development experience with additional capabilities tailored to your project's needs.

These dependencies and optional integrations are key in providing a robust setup for working with tRPC and React Query (along with Prisma, Zod, and react-hook-form, next-auth, zustand if opted) in a Next.js project.

Example

To demonstrate how you can use create-next-app-trpc, here's a basic example:

"use client";

import { trpc } from "./_trpc/client";

export default function Home() {
  const greeting = trpc.greeting.useQuery();
  return <h1>{greeting.data ?? "No data"}</h1>;
}

This example shows how to set up a simple tRPC router using create-next-app-trpc

Documentation and Resources

For comprehensive guides and best practices, refer to the official documentation of each tool and library integrated with create-next-app-trpc:

For video tutorials, check out

Contributing

Contributions to create-next-app-trpc are welcome. If you have any suggestions, bug reports, or pull requests, feel free to open an issue or submit a pull request on the repository.

License

This project is licensed under the MIT License. The full license text can be found in the LICENSE file in the project repository.