Should I add yarn-error.log to my .gitignore file? - node.js

Yarn has created yarn.lock and yarn-error.log.
I have been told not to add yarn.lock to my .gitignore file because it locks down the packages.
Should I ignore the latter?

It makes sense to ignore the yarn-error.log—log files are only useful to debug your own copy of the code, so there's no need to upload it to the repository.
File should be uploaded to your repo when they are useful or needed to build your project. The yarn-error.log (as the name suggests) is an error log, so it's never read by Yarn. The whole point of it is that you read the log to find out what went wrong, and if you've not had any errors, it might not even exist at all.
gitignore.io, a service which generates .gitignore files, include yarn-error.log and yarn-debug.log in their .gitignore file for Node:
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
It may be wise to follow their example if you're not sure what you need—most pre-made .gitignore files have thought this issue through and concluded that logs should generally be ignored.

Since writing this I realise all log files are typically ignored in the .gitignore file with this entry:
*.log

Its system specific log file for the user. So it should be added to gitignore.

some times we find error that is "cannot find symbol" when build the project.
to solve that problem we add this file to our root project.
we can use it in our project where all all files and folder are available.
just above to yarn.log file

Related

Uploading a reactjs code in github, without the node_modules folder

I want to upload a react app in github. But, I dont want to HOST IT. I only want to keep the codes there. But while uploading, I had problem with uploading the node_modules folder. I searched other repo, and even there node_modules folder wasn't present. Still their code could be used by running a command called npm install or something similar to that.
What are the steps to upload My ReactJS Code without uploading the node_modules. But in such a way, by which anyone can install all the node modules by npm install or something similar to that?
To tell git to exclude something in your project, you use a .gitignore file. In the .gitignore file, you can add patterns to files or folders and git will not track any of those files.
Here is a template for Node projects given by GitHub. It excludes the node_modules folder. Put it in your project root and remember to rename it to just .gitignore (note the period in front).

hiding .env file within a project

This is my file directory structure
project
client
server (has the .env file with credentials)
How can I hide credentials in the .env file when I push to github? I know that you have to use .gitignore but how would that work since my .env is not in the root directory?
UPDATE
I tried doing what the response said but the .env file still did not disappear in my repo.
Here is what the .gitignore file reads:
.env
.idea
**/node_modules
data
yarn.lock
You can just add .env to .gitignore, then git add .gitignore followed by git commit. This will ignore .env in all subdirectories from future git operations, so the .env file will not be pushed at all to GitHub.
The .gitignore file specifies patterns of a file or directory name, not the explicit path relative to the location of .gitignore in the directory tree. This means that you don't need to specify project/client/.env etc separately.
So, just add this to your .gitignore:
.env
If you already accidentally pushed your .env file and it contained sensitive credentials, revoke those credentials immediately and treat them as if bots have already scraped them, and follow the instructions here: Removing sensitive data from a repository
As a side-note, if your application requires environmental variables to work, it's customary to document them in your README. I also often see a file named like .env.sample or something similar, which is a boilerplate for each developer's own .env file. This file usually just contains the keys without the values, so other developers know which variables they need to set up.

git status is not showing my changed files

I have a Node.js project and have imported a few Node modules. The git_status command shows the files that I changed in the project. I have also changed some files under the node_modules directory but those are not shown. The node_modules directory is shown as untracked.
Untracked files:
(use "git add <file>..." to include in what will be committed)
node_modules/
src/js/main-release-paths.json
I have changed only one file in node_modules:
node_modules/#oracle/grunt-oraclejet/node_modules/#oracle/oraclejet-tooling/lib/serve/connect.js
How can I track this file?
You shouldn't add the node_modules folder to git then it's managed bei the npm command. So remove that folder and use the npm install command.
When you have added something in that folder it's shown as changed, if you had first added some files. So i hop that folder is in your .gitignore file and ignored. You should check that.
Assuming you have git repo, Please check the .gitignore files inside your project. Entries in .gitignore will be ignored by Git and will not show up when you do git add.
Adding the file to track
This is most likely not a suitable approach (read below). However , if you really want to do it:
In order to track a file nested under node_modules, you should add the directory. All of its content will be staged in git
git add node_modules
Recommended approach
You probably don't want to track the contents of node_modules directory, because:
running npm install will wipe your changes
hundreds or thousand files are likely to end up present in that directory
tracking package.json and package-lock.json in git is sufficient, then populate node_modules using npm install command.
You are not supposed to modify files located in node_modules directory directly. Instead, fork the module in question, modify it, and:
either publish your own version in npm
or reference it as a git repository inside package.json (how-to)
Then, also add node_modules directory to the .gitignore file.
If the whole directory is untracked, git status will show only the directory. Because it's untracked, there is no meaningful difference to git between changed and unchanged files in there.
Other answers have already addressed that tracking node_modules is nota good idea. Of you want to track your changes to modules, consider cloning the module repo and including it as a git submodule.
It should be inside .gitignore file. A .gitignore file should be committed into your repository, in order to share the ignore rules with any other users that clone the repository.

How to add a folder to the .gitignore

Maybe my Googling skills are lacking but this seems like a question that should give me back thousands of hits and yet, I can't find a straight answer.
Simple as this:
I do constant pushes to github to share with a remote developer. We both have npm and bower installed. No need to push these huge folders to github all the time. My node_modules are ignored. But I can't seem to get gitignore to ignore my bower_components folder
I'm not too savvy on cmd, I barely scratch the surface so if you ar going to suggest that, please don't assume I know what you are talking about. Otherwise if it is as easy as adding it to the file itself using an IDE, well, I did that and no cigar. Here is my .gtignore file for your review
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing- task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules
jspm_packages
bower_components
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
Am I missing anything? How do I make the bower_components ignored?
Thank you
If you want to ignore folder, you need a trailing slash:
bower_components/
Then check if the rule apply with git check-ignore -v (the -v is important if you want to see the exact .gitignore file and line which causes a file to be ignored)
git check-ignore -v -- bower_components/afile
If that does not apply, then remove the content of that folder from the history of that repo:
git rm --cached -r -- bower_components/
git add .
git commit -m "Remove bower_components folder"
Then the .gitignore rule will take effect immediatly.

Failed to find package.json. Node.js may have issues starting. Verify package.json is valid or place code in a file named server.js or app.js

When I try to upload my Node.js project on Elastic Beanstalk I obtain the following error:
Failed to find package.json. Node.js may have issues starting. Verify package.json is valid or place code in a file named server.js or app.js.
However, I have the package.json in the main directory.
A couple of people were zipping the parent folder incorrectly. You need to select all the contents of the folder and zip those.
https://forums.aws.amazon.com/message.jspa?messageID=477087
https://forums.aws.amazon.com/thread.jspa?threadID=130140&tstart=0
While uploading the .zip file (Nodejs application) we need to select all the files in the folder, then zip it as shown in below screenshot.
Then upload the Nodejs(zip file) project in AWS Elastic Beanstalck.
I had the same issue running a zip of node js boilerplate. It worked when I removed .git and .idea directories and n.gitignore file from the zip.
You need to zip the build directory, to do so inside that directory you can zip -r upload.zip . (do not forget the dot at the end for current directory).
So in that directory you need to have your index.js or server.js as EB looks for how to run the app in the directory only and will not look into folders src, dist etc.
This can be the packaging issue. You will need to go inside the project and compress altogether as provided in the screenshot:
If you use eb cli, make sure you have git committed all the changes.
If you do zip and upload, make sure you don't zip the parent folder but selecting all files and zip.
In my case i have found a wrong copy of the folder .elasticbeanstalk with inside another config.yml
example
root_project_folder
.elasticbeanstalk/
config.yml
public/
.elasticbeanstalk/
config.yml
and when I started the "eb deploy" command it failed because use the wrong public/ folder as a ROOT
removing the public/.elasticbeanstalk/ have resolved my issue
Ciao

Resources