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

next-codegen

v1.0.3

Published

- Quickly scaffold page and api routes from the command line - Supports all Next.js features (dynamic routes, TypeScript, src directory, new data fetching methods, you name it!) - Super fast and tiny (don't even install if you don't want)

Downloads

5

Readme

next-codegen

npm version

Community-run code generation for Next.js. Quickly create pages and api routes from the command line.

next-codegen screenshot

Features

  • Quickly scaffold page and api routes from the command line
  • Supports all Next.js features (dynamic routes, TypeScript, src directory, new data fetching methods, you name it!)
  • Super fast and tiny (don't even install if you don't want)

Next-codegen aims to keep in sync with Next.js releases to ensure feature parity. This makes it a great way to keep up with api changes to Next.js. We also link to the wonderful Next.js documentation as much as possible to provide additional help and context.

Installation

Next-codegen can be used via npx or installed globally. You can install it locally too, whatever works for you.

> npx next-codegen
> yarn add -g next-codegen
> npm i -g next-codegen

You can then use yarn generate or npm run generate to use next-codegen.

How to use next-codegen

When you run next-codegen you'll be asked if you'd like to create a new page or a new api route. Then you'll be asked to name the route. If you're creating a page route, you'll be asked what type of data fetching you'd like to use.

All prompts can be added as commands and flags instead. Here are some examples:

> next-codegen page about-us
> next-codegen api 'auth/login/[user]'
> next-codegen page 'blog/[category]/[slug]' --ssg

So, you can use next-codegen api for api routes, next-codegen page for pages, and use the --ssg (getStaticProps) or --ssr (getServerSideProps) flags to specify the data generation type for your page. Pretty neat!

TIP: Most terminals have special treatment for square brackets in arguments, so make sure you wrap any route names in quotes when using the api and page cli commands. Don't add quotes when using the prompts!

Zero configuration required

Much like Next.js, next-codegen will automatically infer settings from your project. This includes:

  • src folder detection for pages/ vs src/pages/
  • TypeScript detection

As next-codegen grows, check here for even more inferred settings and some possible customization in the future.

Frequently Asked Questions

(Well, nobody's asked them yet, but still...)

Why another custom code generator?

We favor small, specific tools with a single purpose over tools that try to do everything for everyone. By making this code generation tool specific to Next.js we are able to make assumptions about user's projects and avoid a lot of boilerplate and configuration.

Plop is a great code-generation tool that I would highly recommend. However, its quite large (1.2mb), which makes it unsuitable for use in a binary tool called with npx, which downloads the code on every invocation. We wanted next-codegen to be as easy to use as possible without requiring a lot of custom config or even installing the package.

That being said, plop.js is an excellent tool and you could easily run it alongside next-codegen or write your own Next.js-specific plopfile. Entirely up to you!

Why doesn't this do [x]?

I'd love it to! Create an issue or pr and I'll take a look. I'd love for next-codegen to be as robust as possible and as customizable as necessary, but with sensible defaults that make sense for most users.

Who are you?

I'm @zackkrida, a full-stack remote software engineer who uses Next.js in production every day. I wrote next-codegen for myself to make simple tasks easier, and figured it was worth sharing.

I'm always looking for part-time and contract remote work, so feel free to drop me a line at [email protected] or on twitter @zackkrida