This guide will walk you through the process of setting up and running a basic Next.js application.
Before you begin, make sure you have the following installed on your machine:
Open your terminal and run the following command to create a new Next.js app:
npx create-next-app my-next-app
This will scaffold a new Next.js app in a directory called my-next-app
.
Change into the newly created app directory:
cd my-next-app
Start your Next.js app by running the following command:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
This will launch your app in development mode. Open your browser and navigate to http://localhost:3000 to view your app.
Open the pages/index.js
file in your code editor. This is the default landing page of your app. Make changes to see them reflected instantly in your browser.
When you are ready to deploy your app, build it using the following command:
npm run build
This will create an optimized production build in the out
directory.
To run your app in production mode, use the following command:
npm start
Your app is now ready for production deployment.
For more information on Next.js and its features, refer to the official documentation.
That's it! You've successfully set up and run a Next.js app. Happy coding!