What is create-next-app?
The create-next-app npm package is a command-line tool that allows you to quickly set up a new Next.js project with a default configuration. It simplifies the process of bootstrapping a Next.js application by providing a pre-configured project structure, dependencies, and scripts.
What are create-next-app's main functionalities?
Bootstrap a New Next.js Project
This command initializes a new Next.js project in a directory named 'my-next-app'. It sets up the project with a default configuration, including necessary dependencies and scripts.
npx create-next-app@latest my-next-app
Use a Custom Template
This command initializes a new Next.js project using a custom template. In this example, the 'blog-starter' template is used to set up a blog application with pre-configured settings and components.
npx create-next-app@latest my-next-app --example blog-starter
TypeScript Support
This command initializes a new Next.js project with TypeScript support. It sets up the necessary TypeScript configuration and dependencies, allowing you to write your application in TypeScript from the start.
npx create-next-app@latest my-next-app --typescript
Other packages similar to create-next-app
create-react-app
Create React App is a similar tool for bootstrapping React applications. It provides a default project structure, configuration, and scripts for building React applications. While create-next-app is tailored for Next.js, which includes server-side rendering and static site generation, Create React App is focused on client-side rendering.
vue-cli
Vue CLI is a command-line tool for scaffolding Vue.js projects. It offers a similar experience to create-next-app but for Vue.js applications. Vue CLI provides a range of templates and plugins to customize the project setup, whereas create-next-app is specifically designed for Next.js.
angular-cli
Angular CLI is a command-line interface for Angular applications. It helps in setting up a new Angular project with a default configuration, similar to create-next-app for Next.js. Angular CLI includes features like code generation, testing, and deployment, tailored for Angular applications.
Create Next App
Create Next.js apps in one command.
If you run into any issues or have feedback, please file an issue
Overview
npm install -g create-next-app
create-next-app my-app
cd my-app/
npm run dev
Open http://localhost:3000 to view your running app.
When you're ready for production, run npm run build
then npm run start
.
Start Coding Now
You don't need to install or setup Webpack or Babel.
They come packaged with next
, so you can just start coding.
After running create-next-app
, you're good to go!
Getting Started
Installation
Install it once globally:
npm install -g create-next-app
You’ll need to have Node >= 4 on your machine.
We strongly recommend to use Node >= 6 and npm >= 3 for faster installation speed and better disk usage. You can use nvm to easily switch Node versions between different projects.
You don't need to use Node as your primary backend. The Node installation is only required for Create Next App and running the Next.js server in development/production.
Creating an App
To create a new app, run:
create-next-app my-app
cd my-app
It will create a directory called my-app
inside the current folder.
Inside that directory, it will generate the initial project structure and install necessary dependencies:
my-app/
README.md
package.json
next.config.js
components/
index.js
head.js
nav.js
pages/
index.js
static/
favicon.ico
Routing in Next.js is based on the file system, so ./pages/index.js
maps to the /
route and
./pages/about.js
would map to /about
.
The ./static
directory maps to /static
in the next
server, so you can put all your
other static resources like images or compiled CSS in there.
Out of the box, we get:
- Automatic transpilation and bundling (with webpack and babel)
- Hot code reloading
- Server rendering and indexing of
./pages
- Static file serving.
./static/
is mapped to /static/
Once the installation is finished, you can run some commands in your project:
npm run dev
or yarn dev
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any errors in the console.
npm run build
or yarn build
Builds the app for production to the .next
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
npm run start
or yarn start
Starts the application in production mode.
The application should be compiled with `npm run build` first.
Now you're ready to code & deploy your app!
Starting from Examples
There are a ton of examples in the Next.js repo (and growing!) that you can use to bootstrap your app.
To use an example:
- Go to https://open.segment.com/create-next-app#examples
- Search for an example you want and get it's name (looks like
basic-css
) - Run:
create-next-app --example basic-css example-app
- Done 💥
Acknowledgements
We are grateful to the authors of existing related projects for their ideas as inspiration:
Looking for alternatives? Here are some other project starter kits:
Questions? Feedback? Please let us know