1️⃣

4.1 Setting up Next.js

 
 
Next.js is a React Framework designed to enhance React features, providing structure and optimizations to ease the development process and app speed. We'll delve more in-detail to what Next.js can do in later parts of this chapter. Before getting started with Next.js, the development environment must be set up properly. Note that this guide requires a basic understanding of command line/ terminal use.

Steps to set up:

  1. Make sure Node.js is installed. You can download it from the official Node.js website: https://nodejs.org/en
  1. We now create a new directory for our project and navigate to it using the command line or terminal.
  1. Initialize a Next.js as a project dependency by running one of the following:
    1. If you're using npm, run npm install next react react-dom
    2. If you're using Yarn, run yarn add next react react-dom
  1. Create a new directory named pages in the root of your project. This is where we’ll write our Next.js pages.
    1. Inside the pages directory, create a new file called index.js. This will be the entry point of your application and will represent the homepage. We can create additional pages by adding more files inside the pages directory.
  1. In the terminal or command line, run npm run dev or yarn dev to start the development server provided by Next.js, and automatically open the app in the browser.
Open the browser and navigate to http://localhost:3000. We’ll see the "Welcome to Next.js!" message rendered on the page by default.
notion image
We have successfully set up and created our first Next.js page. We will continue to build the application by creating additional pages, components, and stylesheets.

Next Section

2️⃣
4.2 Creating, editing, and navigating pages
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.