How to create a React app directly in the current folder.
Install React In an already created folder.
Background
I was given a task to setup React using create-react-app for a team project with the project repository already created.
To avoid the React default behavior of creating a new folder, I had to find a way around the problem.
I had different approaches to solve the problem but I was finally able to get an easy approach which I will be explaining below.
Solution
The default way of creating a react app with CRA is:
$ npx create-react-app your-app-name
This comes with a folder named after your-app-name
.
To solve the above problem, use the command below:
// run this at the file directory
$ npx create-react-app .
Note
Please pay attention to the full stop(dot) at the end of the command, it corresponds to the current directory.
The above works only if your current directory complies with npm naming restrictions.
The directory must:
- contain only URL-friendly characters.
- contain no capital letters.
E.g the folder cannot be named MY App Name
; it should be my-app-name
.
Conclusion
You can create a new react app using CRA(Create-React-App) without generating a new folder.