Skip to main content

200. Create New next.js App

Create New App

npx create-next-app hello-world
npm run dev

Create with Typescript

npx create-next-app hello-world --typescript
npm run dev

Add Typescript to Existing App

cd app_root
touch tsconfig.json
npm run dev
  • The above last command(npm run dev) will install all the necessary libraries needed or install it yourself with the below code
npm install -D typescript @types/react @types/node
npm run dev
  • finally change any .js files to .ts

Build and Server Nextjs Production

npm run build #creates or update next folder

Serving Options

  • Suitable for all cases of next.js rendering
    • can be used in all cases of next.js (SSG,SSR,ISR, Client side fetching)
    • Requires node.js server
npm run build
npm run start #next start
  • if your applications is using SSG or Client side fetching only
    • ==cannot be used in ISR or SSR==
    • exports all your pages to static HTML files that you can serve without the need of a node.js server
npm run build
next export
#then point the static server to index.html or main html page