DEV Community

Alvin Chui
Alvin Chui

Posted on • Edited on

2 2

Front-End Workflow for Next.js

1) Setup

yarn create next-app
# OR
npx create-next-app
# AND
npm i -g create-next-app
Enter fullscreen mode Exit fullscreen mode

2) Pages & Routes

  • Home
  • About
  • Others...

3) Layout Components

  • Navigation Bar
  • Header
  • Footer
  • Layout

4) Styling

  • Choosing a Theme
  • 404 Error Page
  • Responsive Design

5) Database

  • MongoDB
  • REDIS
  • MySQL
  • Others...

6) Fetching

// Basic Example
import fs from "fs";
import path from "path";

export async function getStaticPaths() {
    const files = fs.readdirSync(path.join("blogs"));

    const paths = files.map((filename) => ({
        params: {
            slug: filename.replace(".txt", ""),
        },
    }));

    return {
        paths,
        fallback: false,
    };
}

export async function getStaticProps(context) {
    const blog = fs.readFileSync(
        path.join("blogs", context.params.slug + ".txt"),
        "utf-8"
    );

    const content = blog;

    return {
        props: {
            content,
        },
    };
}


Enter fullscreen mode Exit fullscreen mode

7) Dynamic Routing

  • /Content/index.js
  • /Content/[slug].js

8) Testing

  • ES6 or ES2016+
# Dependencies
npm install --save-dev eslint
npm install --save-dev eslint-config-next

npm run lint
Enter fullscreen mode Exit fullscreen mode
  • QUnit
npm install --save-dev qunit
Enter fullscreen mode Exit fullscreen mode
  • Mocha experience
Matching "Test" file structures
Enter fullscreen mode Exit fullscreen mode
  • Others...

9) Deployment

OTHERS

  • SEO
# Basic Example
npm i --save-dev next-seo
Enter fullscreen mode Exit fullscreen mode
  • Optimization

Image description

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay