Next.js setup
getting ourselves ready (quickly) with Next.js
Let's begin a clean Next.js setup with only the following:
Command line (with node and npm installed)
Installation
Let's start on the command line by creating a folder (let's call it
myproject)
In the project folder, enter the following command:
Next, install Node + TypeScript (with types) + React (with its virtual DOM) + Next:
The following things will appear in the project folder:
package.json
= a project configuration and dependency list (which will we look at later)dependencies are those third-party scripts
node_modules
= a folder with all the dependency scripts
Infrastructure folders and files
Now, let's create a folder called
app
at the project folder's root levelwe will store most of our front-end code in this folder
Public folder
We could also create a folder called
public
at the root level to store static assets (such as image files):a file called
logo.png
would have a relative path of/logo.png
anything in a subfolder of
public
(e.g.logos/logo.png
) would have a relative path of/logos/logo.png
.gitignore file
If using Git, we should also create a
.gitignore
file at the root level, with the following content:
This avoids making the repo too large with any third-party scripts we may use in the project
as a refresher, the
package.json
andpackage-lock.json
already provide the information about third-party scriptsanyone who clones the repo can then simply run
npm install
npm will look into those json files and install the scripts!
We can also include any other files we do not wish to display publicly on our GitHub repo
in this example, we included
.env
which typically contains private API keys
Root layout
Then, in the
app
folder, let's create a file calledlayout.tsx
(a TypeScript file!):
That should provides us with a minimal front-end foundation:
On the next page, we will create our first page (component)
We will then run it from a local server on a browser
We can then deploy it to the cloud with a URL that anyone on the internet can access!
Last updated