DEV Community

Cover image for Introduction to Next.js
Vidushi Agrawal
Vidushi Agrawal

Posted on

Introduction to Next.js

Delving into Next.js is essential for any seasoned developer. This robust React framework brings forth a myriad of benefits. Mastering Next.js equips you with the tools to craft web applications that are not just efficient and scalable but also embrace modern web development practices.

What is Next.js?

Next.js is a React framework for building full-stack web applications. It offers an excellent developer experience and comes with many built-in features.

Getting started with Next.js

Prerequisites:

Before we begin, make sure you have a strong knowledge of HTML, CSS, JavaScript, and React JS.

Create your first Next.Js app:

Open your terminal and use the following commands to create a new Next.js project:

npx create-next-app my-nextjs-app
cd my-nextjs-app
Enter fullscreen mode Exit fullscreen mode

Replace my-nextjs-app with your preferred project name. This will set up a basic Next.js project structure for you.

Exploring the Project Structure:

Only files & folders inside the app folder are considered for rendering.
page.js: This file is used to render the pages. This file defines the content of the page.
layout.js: This file defines the shell around one or more pages. It runs HTML and body tags. We don't have a head section in the layout.js's HTML tag as the title and description are defined in "metadata".
Metadata-Example
icon.png: When we will define this then this image will be considered a favicon.

Start the Development Server:

To run the local server-

npm run dev
Enter fullscreen mode Exit fullscreen mode

Create a new page:

In the app, add a new directory about and add a new page.js file.

About Page folder

/about/page.js

export default function AboutPage() {
  return (
    <main>
      <h1>About Us</h1>
    </main>
  );
}
Enter fullscreen mode Exit fullscreen mode

This will create a http://localhost:3000/about page. The content should be written on the page.js file.

Conclusion

Bravo! You started learning the next.js and created a new page. Feel free to create more pages and explore. Keep learning and experimenting!

Top comments (0)