Installation of Next.js

First, create an empty project folder and initialize npm in it:

$ mkdir next-js-condensed$ cd next-js-condensed$ npm init

After that, let's install the Next.js package:

$ npm install nextjs@latest --save-dev$ npm install react@latest react-dom@latest --save

We save Next.js to devDependencies to clearly separate dependencies for the client and for the server. Server-side dependencies will be in the devDependencies section; the client's will be in the regular section.

If you're using Git or any similar source control tool, it makes sense to add an ignore file that will remove the build artifacts folder from source control. We show an example .gitignore file here:

.DS_Store.idea.next.vscodebuildcoveragenode_modulesnpm-debug* ...

Get Next.js Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.