How to remove node modules in react project with commands ?

If we are using yarn, We need to use the following commands in the terminal to remove the node modules and cleanup the cache

rm – Rf node_modules

yarn cache clean

yarn install

If we are using npm, We need to use the following commands in the terminal to remove the node modules and cleanup the cache

rm – Rf node_modules

npm cache clean –force

npm install

Breakdown of the Command “rm – Rf node_modules”

  • rm: The command used to remove (delete) files or directories.
  • -r (or -R): Recursive flag. It instructs the terminal to dig inside the folder and delete all nested files and subdirectories.
  • -f: Force flag. It bypasses any confirmation prompts and ignores non-existent files.
  • node_modules: The target folder holding your local Node.js package dependencies.

If we want delete package-lock.json or yarn.lock file then we need to use either

rm -rf node_modules package-lock.json

(or)

rm -rf node_modules yarn.lock

How to publish a package to npm ?

To publish a package to npm, we should follow the following steps.

STEP 1 : Make sure your project have package.json file something like this.

STEP 2 : update your entry file with required functionality. Here entry file is index.js as we defined in package.json as “main”: “index.js”. Following is some example code.

STEP 3: signup to npm using https://www.npmjs.com/signup

STEP 4: Now login to npm using the following command in the terminal

STEP 5: publish the package using the following command. (Make sure package name is unique)

Finally you are able use that package anywhere by just installing with the following command