How to correctly push changes to Heroku - node.js

Currently whenever I make a change to some code I do the following in terminal:
git init
git add .
git commit -m "Some changes"
git push heroku master
I am not 100% certain, but this seems like it is redeploying the entire project and installing all packages again. If this is the case is there a way to only push the changes made?
For example, if I change one line of code, I just want to push that one file with the change, not the entire project again.

It depends how you're packaging the app, e.g. with webpack.config. Typically you'd package and deploy the entire project to the server each time. This is the correct way to do it (rather than just trying to replace one file), so that you can do project-wide actions like minifying code, processing your CSS, etc. The server would not download/install external packages that are already there unless you specify a different version in your package.json file.

git init only be oncethen every time you make a change just run
git add. (add all changes)
git commit -m "commit"
git push origin master

It's because react has to do some of its magic before Heroku can deploy it properly. That magic includes installing the node modules, compiling all the source files, and then optimizing everything before outputting the build folder with everything in it. There's not a 1:1 relationship between the one line in one file you changed and the build output - react requires a re-build.

Related

Add existing NodeJs (node, Express, monodb,...) project to existing a NX monorepo (Angular)

Has anyone experienced how to add an existing NodeJS API to an existing (Angular) Nx Monrepo?
Unfortunately the manual doesn´t help me so much
https://nx.dev/migration/manual
The process of migrating a repo into your mono repo requires a few manual steps. I think there would not be a simpler way to do it.
Assuming your node project does not share files with your current monorepo, this should be the steps:
on your node repo, create a branch 'to-monorepo' and in it, move all the files to folders that match the nx folder structure and push the commits to it.
remove your package.json file (we will later merge it with the monorepo's one)
once the folders match the nx folder structure, time to merge into the monorepo. From the monorepo add the remote of the other repo
git remote add node-repo <your git repo's node url>
at the monorepo folder, checkout your master
run a pull to make the node repo branches be available in the monorepo
git pull
create a new branch 'merging-node-repo' on your monorepo.
merge the branch node-repo/to-monorepo into your merging-node-repo branch, preserving the history:
git merge node-repo/to-monorepo --allow-unrelated-histories
push your new branch (all the code and its history will now be listed in this new branch)
remove the remote node-repo from your local monorepo configs
git remote rm node-repo
manually merge all the node repo's original package.json file dependencies into the monorepo's one, and run npm install from the monorepo. This way your package-lock.json file is updated. Once you are done, create a commit and push it.
this last step is more tricky. You have now to manually update the monorepo's config files to allow nx to start managing it. This is where the link you had in your question might help. Once you are done, create a commit and push it.
With these steps you can then merge your merging-node-repo branch into master.
I recommend you to create a separated nx workspace with a nodejs project on it. This helps you with having a baseline for all the necessary nx configurations and dependencies.
You might want to make sure your project works via nx commands from this separated workspace; this way you will have a better chance of getting configurations of your monorepo right.
Hopefully this gets you started.
Here is a solution that I wrote and used to import multiple repos into a single monorepo, under whatever subdirectories are wanted, while maintaining commit history:
https://github.com/marcuswestin/monorepo-merge
I've also found two other scripts that look like they might work, but I haven't tried them:
http://choly.ca/post/git-merge-to-monorepo/
https://github.com/ksindi/monoreaper

Executing .git commands inside electron without having git installed

I am trying to get some git information (for instance command hash) from an electron app. I am reading a file from a certain path and I want to check if this file inside a repo then I will get the super project and get the commit hash.
This is doable if the git is installed on the machine , but if not then this will fail.
I can deal with file paths and get to .git folder and get information from it, but still I prefer if there is another way.
I tried to install npm nodegit, but it has its problems with electron and webpack.
Also there is git-revision but its methods are simple and I need more functionalities (like getting the super project )
Is there a way or a library to achieve that if we need to run the project on machine with no git installed on it?

Node.js HEROKU app doesn't update after pushing

So I a deployed a Node.js website to Heroku earlier (through Github) and today I made a few changes. I did the same git add . git commit -m 'changes' git push commands but the website on Heroku hasn't changed. Automatic deploys are ON. The code on my Github changed and is correct.
I also used git push heroku master and heroku config:set NODE_MODULES_CACHE=false , it doesn't update the code. Website still the same, like at first deploy.
Also did purge cache.
heroku releases checks out. And I checked the file with heroku bash on the Heroku servers, the file is also updated there. Still, I can't see the changes on the website. Tried different browsers, phones, incognito... And I only use master branch.
FIXED IT:
npm run build in the client folder. Even though I did it already before my first deploy, have to do it again after the changes. Then you can push, commit, deploy, whatever...

Changes not showing up in NodeJs/ReactJs apllication running on Heroku?

I have made changes to some css and js file in my Node-React apllication which is deployed on Heroku. But the changes are not showing up when I git add . the project on heroku. ALthough the changes are not coming up when I run the project locally.
Any help would be appreciated on what could be the possible cause on the changes not getting deployed?
You need a few more commands in your deployment workflow.
The git add . command is putting your local changes into staging.
You also need to run git commit -m 'your commit message' in order to commit those local changes to your local git repository.
Next, you need to run git push to push your local repository to the remote repository it is linked with.
Effective use of git is one of the most useful things you can teach yourself as a developer. It will enable you to contribute effectively to a team when the time comes. Here's a good starter article: Basic Git With Examples.

NPM - Fork module, change code and send PR to author

For a particular npm package I want to create a PR with some code changes.. The author of the package told me, to create a PR from a particular branch..
All fine so far, I can change the url + branch inside the package.json and load the specific branch as npm module.. Also npm install works fine.
But then I want to change some code in that node_modules/module folder and create a PR from the code changes..
The only thing I can make to work for sure, is to first fork the entire repo in a separate folder, than checkout X branch, than change code, copy/past it to the node_modules/module folder every time I wanna check my code changes.. And than push it to my personal github page, and from there create a pull request..
But its really frustrating to copy/past my changes every time to the node_modules/module folder.
What is the best way to change a npm package and create PR for it, while still keeping the code inside the node_modules folder, so code changes can be checked?
Thanks!
This is the proper thing to do. Fork the github repo, create the branch that the guy told you, make the changes and send a pull request.
If you want to work in parallel and assuming that there are no compilation steps that npm should do, you can clone the forked repository within your node_modules and work directly there. As soon as you will make and commit the changes then you can send the pull request.
EDIT
I would say that this can be an acceptable approach that can work on linux:
~/projects/your-project/node_modules
~/projects/your-project/node_modules/name-of-module (symlink to the ~/projects/your-forked-cloned-repo)
~/projects/name-of-module (It should be your forked repo that you 've cloned from github/assembla etc)
~/projects/node_modules (symlink to the ~/projects/your-project/node_modules)
You're looking for npm link:
$ git clone your/npm-repo-fork
$ cd npm-repo-fork
# Link the project as a local dependency
$ npm link
$ cd ../some/other/project
# Use the linked project
$ npm link name-of-npm-dependency
# Now you can edit npm-repo-fork and the changes
# will be picked up by some/other/project
$ cd ../../../npm-repo-fork

Resources