Reputation: 470
I have completed my project.
My stack :
Front-End UI => Reactjs
Back-End => Nodejs/Expressjs + MongoDB
And below is my project structure
containing both the folders:
project_Name > client + server
project_Name
is the main folder
client
and server
are the separate folders both are inside project_Name
folder.
And inside client
and server
folder I have installed the respective npm modules (reactjs + nodejs)
My API end point
is running on localhost:8000
and reactjs
on localhost:5000
So now I want to add my project to github
repository.
I am confused how to achieve that?
Do I need to push both client and server side code on separate 2 different gits?
Or
I need to upload just project_Name
folder containing both side project files?
But is it so then how can I do that?
Since before pushing to git
, the directory should have the package.json
file and node_modules
which will be only inside the client
and server
side folders.
These are the git
commands to push the project I am using:
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/vik.........git
git push -u origin main
But I don't know in which folder I have to initiate the repository
first?
Let me know the solution please .
Thanks!
Upvotes: 6
Views: 12533
Reputation: 1
I got your problem ...
You just need to navigate to project_name
in the terminal and then
run the command git init
and then you can track and push all the files of client and server without creating separate git for client and server
Upvotes: 0
Reputation: 797
Finally i found the answer after 2 hours
to push your folder in format like this:
-projectName: folder
- frontend: folder
- package.json
- backend: folder
- package.json
- package.json
you have to follow the following steps:
git init
ouside the client and server folder.git
folder from client folder if you using any frontend
framework like (reactJs, nextJs)git add .
, use git add ./client
it removes the all node modules and only puts the json file to the github.git commit -m"initial commit"
,git remote add origin lkdjfhgoiuehg.git
, git push origin master
Then you are good to go!
Upvotes: 3
Reputation: 432
After creating two folders named client and backend in a root folder(suppose the name is: my-project). Now we would like to push our code to remote like this.
a) create a repo named my-project in GitHub(same name as the root folder) b)checking in the terminal of my local to check if it is in the root or not. c)from root: my-project % run all the following commands.
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/vik.........git
git push -u origin main
d) now from the root in each folder[client and backend] create a .gitignore file and write node_modules to ignore node_modules if needed.
e)git add .
f)git commit -m 'all codes is pushed to remote'
g)git push origin main
Now all codes are in the remote. If any code is changed for example in the client.
a) cd client
b) git status
c9 git add ./ file name
d) git commit -m 'client code is pushed'
e) git push origin main
client code is now updated in remote too. Hope it would help.
Upvotes: 0
Reputation: 11
just copy and paste the .gitignore file in both frontend and backend folder, git will not upload node_modules folder in git repository.
Upvotes: 1
Reputation: 129
I solved this problem by adding the .gitignore file in the root folder (in same level as client and server) and inside that this line: node_modules/
this will ignore node_modules of both client and server.
after that initialize git:
Now you can visit GitHub repositories and confirm there isn't node_modules folder anymore
Upvotes: 0
Reputation: 151
If your project that you created has it's own folder then what you would need to do is:
Root Folder: Project ./client ./server
It'll add all your files in one go, so don't worry so much and it won't push any empty folders.
There's some instances where create-react-app, will create a git repo on it's own. On your file explorer look for the hidden files, and be sure to delete that .git folder in your client before pushing your stuff, it'll throw you an error.
run NPM install on your main folder, it'll create a package.json for you. Try not to think about it so hard and take it slow.
Hopes this helps!
Upvotes: 8
Reputation: 201
I think you should use this structure:
-projectName: folder
- frontend: folder
- package.json
- backend: folder
- package.json
- package.json
For executing the app you can use github actions:
https://docs.github.com/en/free-pro-team@latest/actions
https://github.com/features/actions
OR
You can also use services like heroku or firebase, see my project (it is just a simple project for resolving this problem you are asking for)
https://github.com/simCecca/InformationVisualizationWorldWide
The structure is:
-projectName: folder
- frontend: folder
- package.json
backend code
package.json // containing the BE dependencies and the dependencies for the
deploy in heroku in this case
I hope I responded to your question, if I'have not, please reply to this response
Upvotes: 3