How to Create a Next.js App in the Current Directory
You can initialize a new Next.js app in the current directory by using a dot (.) for the path when running the npx create-next-app command. There is a mandatory requirement is that the name of the current folder must not contain special characters, spaces, or capital letters.
npx create-next-app .
I ran the command above inside a folder named example and here’s what I got:
If you want to create a Next app with TypeScript, just add either the –ts or –typescript flag:
npx create-next-app . --typescript
After the initialization is complete, you can boots your project up by running the following command (without switching directory):
npm run dev
That’s it. Further reading:
- Next.js: Reading and Display Data from a Local JSON File
- How to use Tailwind CSS in Next.js
- Next.js: Retrieve URL Params from Dynamic Routes
- Passing data via a Link component in Next.js
- How to Correctly Use Bootstrap 5 in Next.js
- React: 2 Ways to Open an External Link in New Tab