banner



Can;t Upload Node Js To Github

Author avatar

Set up a GitHub Project with node_module

Pavneet Singh

Front end End Web Development

Introduction

The npx create-react-app app-name command is the easiest manner to fix a React template project. It is also an officially recommended approach to fix a React project. The npx command stands for "Node Packet Execute," and uses the latest version of the create-react-app tool to fix upwardly a React projection without installing a specific version of the tool locally.

The npx command is arranged with the node.js packet, and, apart from npx , node.js also simplifies the process of dependency management using npm and packet.json file to rails the list of dependencies. A node_modules directory contains all the React dependencies packages: react , react-dom , and their transitive dependencies like webpack , babal , rxjs , ESLint , etc., to build and run a React project. The node_modules directory is one of the crucial parts of whatsoever node or React project, simply it shouldn't be tracked past the version control arrangement (git) due to its large size. The correct approach is to track the packet.json file, and utilize the npm tool to regenerate node_modules . This guide explains the steps to fix a GitHub project to manage node_modules directory.

Setting Upwardly a Node Project as a GitHub Repository

The create-react-app control automatically sets up the project as a git repository. It performs the post-obit git commands:

  • git init: This control volition configure the projection as a git repository and creates a .git directory that is used to track the changes fabricated in the projection.
  • .gitignore File: The .gitignore is a subconscious file and tin can exist created manually like whatsoever other file. This file provides the information to git to ignore/untrack files or directories with the defined names or the patterns. For example, /node_modules will ignore the node_modules directory (and its content) in the root directory merely, but node_modules volition ignore the node_modules directory defined anywhere in the project hierarchy. More than details about .gitignore patterns is available on in the official docs. Now the adjacent footstep is to salve the changes into git :

  1. Stage all of the changes for the adjacent commit

  1. Commit/Save the changes into git with a message using -grand flag and commit command
                                      1                    git commit -chiliad "kickoff commit"                                                      

sh

Note: No changes will be staged or committed for the alleged files and folders in .gitignore file.

Once the changes have been committed, the next step is to push the code to a remote repository (on GitHub) via the following steps:

  1. Log in to your GitHub account

  2. Create a new repository by clicking on the + icon and re-create the given SSH link. Don't create any license or readme.md file, otherwise git will force you lot to pull/download the changes first, which tin be done using git pull origin chief --allow-unrelated-histories control.

The --let-unrelated-histories flag should non exist used afterwards with git pull .

New repository

If you oasis't added the SSH key to your GitHub account then either you can use HTTPS link, which volition require you to enter a username and countersign for every push to a GitHub server, or y'all tin can gear up the SSH key by following the steps here.

  1. To push the code to a remote repository, git needs to know the URL of the remote repository.

  • Re-create the SSH URL from GitHub repository:

Clone with SSH

  • Add the remote SSH URL into git remote entries:
                                      ane                    # SSH link ends with .git                                        2                    git remote add origin https://github.com/UserName/RepoName.git                                  

sh

Here remote is a command to manage remote server connection and origin is just a conventional name for remote links.

  1. The final step is to push/move the committed changes to the remote repository:
                                      one                    git push origin master                                  

sh

Setting Up a New Node Project from GitHub

Cloning is a process of downloading a repository from a remote server via using the clone command:

                                      1                    git clone https://github.com/UserName/RepoName.git                                  

sh

The above clone command will download the projection from a remote server locally. The node_modules is non a part of the cloned repository and should exist downloaded using the npm install command to download all the divers and transitive dependencies mentioned in package.json file:

                                      1                    # make sure that you are in the root directory of the project, utilize pwd or cd for windows                                        twocd RepoName                    threenpm install                                  

sh

It will take some time to download all the dependencies into the node_modules directory, and after the completion of this process, the project is fix to run:

Tips

  • A node_modules directory can take up more 200MB, then keeping all node_modules can cause space bug. If you really want to get rid of disk space bug and open to setup node_modules using npm install then the node_modules can exist listed and deleted using the :
                                      i                    # list all node_modules directories in the current path                                        2find . -name 'node_modules' -type d -prune                    3# remove all node_modules directories in the current path                    4find . -proper noun 'node_modules' -type d -prune -exec rm -rf '{}' +                                  

sh

This is an irreversible procedure as node_modules is role of .gitignore , so brand sure to verify the path and git commits before executing the above commands.

  • If node_modules is already a part of a repository then it can exist removed using the git rm -r --cached node_modules command, though make sure to commit and push the changes to the remote server.

Decision

Git and npm provides an easy manner to avoid pushing bulky node_modules to a GitHub repository using the .gitignore file and npm install control. A packet.json file is the source to regenerate node_modules , so this file is plenty to fix a fresh re-create of a Node project. Happy coding!

Source: https://www.pluralsight.com/guides/set-up-a-github-project-with-node_module

Posted by: demarialegis2001.blogspot.com

0 Response to "Can;t Upload Node Js To Github"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel