All you need to know about Package.json as a complete Beginner

Sdílet
Vložit
  • čas přidán 20. 07. 2022
  • All FREE courses - automationstepbystep.com/
    Every Node.js project has package.json file located in the root folder
    Information about NodeJS project
    List of dependencies with version
    How to create :
    npm init
    npm init --y
    package name
    version
    description
    entry point
    test command:
    keywords:
    author:
    license
    git repository:
    dependencies
    Package.json
    records the minimum version needed (with ^ and ~)
    is used for more than dependencies -like defining project info, description, author & license, scripts, etc
    Package-lock.json
    records the exact version of each installed package which allows you to re-install them
    locks the dependencies with the installed version
    When you run npm update packagename - it will update in package-lock.json and not in package.json
    npm install - will install dependencies as per package.json
    npm ci - will install dependencies as per package-lock.json
    Do you need both package-lock.json and package.json? No
    Do you need the package.json? Yes
    Can you have a project with only the package-lock.json? No
    Difference between tilde (~) and caret (^) in package.json
    On npm install get the latest minor or patch version of the dependency mentioned in package.json
    ^ install the latest minor version - 1.x.x
    tells npm that if someone clones the project and runs npm install then install the latest minor version of the package in his node_modules
    ~ install the latest patch version - 1.2.x
    tells npm that if someone clones the project and runs npm install then install the latest patch version of the package in his node_modules
    ~1.2.3 will match all 1.2.x versions but will miss 1.3.0
    ^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0
    #PackageJson
    #NodeJS
    ____________________________________________________________
    Stories by Raghav - automationstepbystep.com/stor...
    My Udemy Courses - automationstepbystep.com/udem...
    Every LIKE & SUBSCRIPTION gives me great motivation to keep working for you
    You can support my mission for education by sharing this knowledge and helping as many people as you can
    If my work has helped you, consider helping any animal near you, in any way you can
    Never Stop Learning
    Raghav

Komentáře • 44

  • @_iamrkr
    @_iamrkr Před rokem

    Thank you Raghav. This cleared my doubts. Really appreciate the work you are doing.

  • @yourwelcomematt
    @yourwelcomematt Před rokem +1

    Awesome explanation, thank you!

  • @AshishSaturn
    @AshishSaturn Před rokem

    Very neat and clear explanation. Thanks ...

  • @Mr47CRO
    @Mr47CRO Před 3 měsíci

    Thank you Raghav, you are the best!

  • @ranjitbobade6717
    @ranjitbobade6717 Před rokem

    thank you for clearing all douts

  • @shoebm786
    @shoebm786 Před rokem

    very good. Thanks

  • @gauravpise6393
    @gauravpise6393 Před rokem

    You are great Sir.👍

  • @sudheshsankarkk
    @sudheshsankarkk Před rokem

    Thanks for sharing 🙏

  • @sciab3674
    @sciab3674 Před 5 měsíci

    thanks , good series

  • @smurffronda2951
    @smurffronda2951 Před rokem

    Thanks!

  • @cr7johnChan
    @cr7johnChan Před rokem

    thanks brother

  • @uchidamai4139
    @uchidamai4139 Před rokem +1

    my brain got clear. Nobody explain that detail. Thank you.

  • @dheerakrish214
    @dheerakrish214 Před rokem

    Thanks 🙏

  • @aasraful
    @aasraful Před rokem

    Thanks

  • @sh44ko58
    @sh44ko58 Před rokem

    thanks a looooot bro

  • @aditya234567
    @aditya234567 Před rokem +3

    thanks for the video but you didnt talk about Package-lock.json. please correct the title

    • @RaghavPal
      @RaghavPal  Před rokem

      Hi Aditya, I have mentioned few things in the Description, will plan to make a more detailed video too

  • @ahamedabdulrahman
    @ahamedabdulrahman Před rokem +2

    Is there any way to let dependency to install the latest version automatically? Say am in 1.2.3, when 2.0.0 comes, it should upgrade to 2 and when 3.0.0 comes, it should upgrade to 3.

    • @RaghavPal
      @RaghavPal  Před rokem +1

      Hi, we use ^ and ~ symbols for that and you can use command
      npm-check-updates
      stackoverflow.com/questions/16073603/how-to-update-each-dependency-in-package-json-to-the-latest-version

  • @eagillum
    @eagillum Před rokem

    I had to include "type":"module" in my package.json. After I've typed that in, then what? Do I have to validate that in some way? Because when I run "node transform.js", It's still not acknowledging the syntax stored in "module".

    • @RaghavPal
      @RaghavPal  Před rokem +1

      Hi Erin,
      When you include "type": "module" in your package.json file, it tells Node.js to treat all .js files in your project as ECMAScript modules, which means you can use import and export statements to load and export modules.
      To use the import and export statements, you need to update the syntax of your JavaScript code to be compatible with ECMAScript modules. This includes replacing the require() function with the import statement, and using the export keyword to export variables, functions, or objects from a module.
      When you try to run a JavaScript file that uses ECMAScript module syntax without the "type": "module" flag, Node.js will throw a syntax error.
      To validate that your code is using ECMAScript modules correctly, you can run your JavaScript file using the --experimental-modules flag. For example, if your file is called transform.js, you can run the following command in your terminal:
      node --experimental-modules transform.js
      This will enable experimental support for ECMAScript modules in Node.js and allow you to run your code.
      Alternatively, you can use a build tool like Webpack or Rollup to bundle your JavaScript code and transpile it into a format that is compatible with all browsers and Node.js versions. These build tools can also validate your code and provide error messages if there are any syntax errors or compatibility issues.

  • @ashvithavk
    @ashvithavk Před 4 měsíci

    Hi, So once we upload to git hub and someone else is downloading to their machine from there then they must just `npm install` cmd. thats all?

    • @RaghavPal
      @RaghavPal  Před 4 měsíci

      Ashvitha
      Certainly! When you upload your project to GitHub and someone else downloads it to their machine, they will need to follow a few steps to set up the project:
      1. Clone the Repository:
      - The other person should clone your GitHub repository to their local machine using the following command:
      ```
      git clone
      ```
      - Replace `` with the actual URL of your GitHub repository.
      2. Navigate to the Project Directory:
      - After cloning, they should navigate to the project directory using the `cd` command:
      ```
      cd
      ```
      - Replace `` with the name of the cloned project folder.
      3. Install Dependencies:
      - If your project uses Node.js and has a `package.json` file (which typically lists project dependencies), they can run the following command to install the required packages:
      ```
      npm install
      ```
      - This command will read the `package.json` file and install all the specified dependencies.
      4. Configure Environment Variables (if needed):
      - If your project relies on environment variables (such as API keys, database credentials, etc.), they should set those up in a `.env` file or through other means.
      5. Run the Project:
      - Depending on the type of project (web app, server, etc.), they can use the appropriate command to start the application.
      - For example, if it's a web app using React, they can run:
      ```
      npm start
      ```
      - If it's a Node.js server, they might run:
      ```
      node server.js
      ```
      6. Test the Project:
      - They should verify that everything is working as expected by testing the application locally.
      Remember that the specific steps may vary based on the type of project and its requirements. But in general, cloning the repository and running `npm install` are essential steps to set up the project on a new machine.
      ..

    • @ashvithavk
      @ashvithavk Před 4 měsíci

      @@RaghavPal Thank you for the detailed steps. For cypress for point 5 I can just replace with `npx cypress run` is it

    • @RaghavPal
      @RaghavPal  Před 4 měsíci

      try and let me know

  • @bhagyalakshmibadiginchala38

    Hi Raghav, May I know why I could not add keywords in package.json and Iam getting the error? "keywords": [adjkfjd,kdjfldjfldjfdljfdl,jfdlkfdl],

    • @RaghavPal
      @RaghavPal  Před rokem +1

      Hi Bhagyalakshmi
      The error "keywords": [adjkfjd,kdjfldjfldjfdljfdl,jfdlkfdl] is a syntax error. The keywords property in the package.json file must be an array of strings. The strings in the array must be separated by commas.
      Here is an example of a valid keywords property:
      ```
      "keywords": ["keyword1", "keyword2", "keyword3"]
      ```
      If you try to add a keywords property to the package.json file that is not an array of strings, you will get the error "keywords": [adjkfjd,kdjfldjfldjfdljfdl,jfdlkfdl].
      To fix this error, you need to make sure that the keywords property is an array of strings. You can do this by adding the following code to the package.json file:
      ```
      "keywords": [
      "keyword1",
      "keyword2",
      "keyword3"
      ]
      ```
      Once you have added the keywords property to the package.json file, you should be able to run your application without getting the error.
      I hope this helps

  • @sairasurve7656
    @sairasurve7656 Před rokem

    You have not explained about package-lock.json. Then why your title mentioning that.

    • @RaghavPal
      @RaghavPal  Před rokem

      Hi Saira, I will check and update, Thanks for letting me know