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

  Рет қаралды 28,292

Automation Step by Step

Automation Step by Step

Күн бұрын

All FREE courses - automationstep...
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 - automationstep...
My Udemy Courses - automationstep...
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

Пікірлер: 50
@_iamrkr
@_iamrkr 2 жыл бұрын
Thank you Raghav. This cleared my doubts. Really appreciate the work you are doing.
@RaghavPal
@RaghavPal 2 жыл бұрын
You're most welcome
@uchidamai4139
@uchidamai4139 2 жыл бұрын
my brain got clear. Nobody explain that detail. Thank you.
@RaghavPal
@RaghavPal 2 жыл бұрын
happy to know this
@yourwelcomematt
@yourwelcomematt Жыл бұрын
Awesome explanation, thank you!
@RaghavPal
@RaghavPal Жыл бұрын
Glad it was helpful
@Mr47CRO
@Mr47CRO 10 ай бұрын
Thank you Raghav, you are the best!
@RaghavPal
@RaghavPal 10 ай бұрын
Most welcome..
@lintasavio1720
@lintasavio1720 2 ай бұрын
Excellent demonstration!!!!
@RaghavPal
@RaghavPal 2 ай бұрын
Glad you liked it!
@ranjitbobade6717
@ranjitbobade6717 Жыл бұрын
thank you for clearing all douts
@RaghavPal
@RaghavPal Жыл бұрын
Most welcome Ranjit
@AshishSaturn
@AshishSaturn 2 жыл бұрын
Very neat and clear explanation. Thanks ...
@RaghavPal
@RaghavPal 2 жыл бұрын
You are welcome!
@sciab3674
@sciab3674 Жыл бұрын
thanks , good series
@RaghavPal
@RaghavPal Жыл бұрын
You are welcome
@gauravpise6393
@gauravpise6393 2 жыл бұрын
You are great Sir.👍
@RaghavPal
@RaghavPal 2 жыл бұрын
Many thanks Gaurav
@sudheshsankarkk
@sudheshsankarkk 2 жыл бұрын
Thanks for sharing 🙏
@RaghavPal
@RaghavPal 2 жыл бұрын
Most welcome Sudhesh
@ygr4943
@ygr4943 4 ай бұрын
شكرا
@RaghavPal
@RaghavPal 4 ай бұрын
موضع ترحيب كبير
@smurffronda2951
@smurffronda2951 Жыл бұрын
Thanks!
@RaghavPal
@RaghavPal Жыл бұрын
Most welcome
@ahamedabdulrahman
@ahamedabdulrahman 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 2 жыл бұрын
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
@shoebm786
@shoebm786 2 жыл бұрын
very good. Thanks
@RaghavPal
@RaghavPal 2 жыл бұрын
Most welcome Shoeb
@dheerakrish214
@dheerakrish214 2 жыл бұрын
Thanks 🙏
@RaghavPal
@RaghavPal 2 жыл бұрын
You’re welcome 😊
@cr7johnChan
@cr7johnChan 2 жыл бұрын
thanks brother
@RaghavPal
@RaghavPal 2 жыл бұрын
Most welcome Randeep
@eagillum
@eagillum Жыл бұрын
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 Жыл бұрын
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.
@aasraful
@aasraful 2 жыл бұрын
Thanks
@RaghavPal
@RaghavPal 2 жыл бұрын
Welcome
@aditya234567
@aditya234567 2 жыл бұрын
thanks for the video but you didnt talk about Package-lock.json. please correct the title
@RaghavPal
@RaghavPal 2 жыл бұрын
Hi Aditya, I have mentioned few things in the Description, will plan to make a more detailed video too
@ashvithavk
@ashvithavk 11 ай бұрын
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 11 ай бұрын
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 11 ай бұрын
@@RaghavPal Thank you for the detailed steps. For cypress for point 5 I can just replace with `npx cypress run` is it
@RaghavPal
@RaghavPal 11 ай бұрын
try and let me know
@sh44ko58
@sh44ko58 2 жыл бұрын
thanks a looooot bro
@RaghavPal
@RaghavPal 2 жыл бұрын
Most welcome
@bhagyalakshmibadiginchala38
@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 Жыл бұрын
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
@arunbm123
@arunbm123 Ай бұрын
hi raghav bhai !!!
@RaghavPal
@RaghavPal Ай бұрын
Hello Arun
@sairasurve7656
@sairasurve7656 2 жыл бұрын
You have not explained about package-lock.json. Then why your title mentioning that.
@RaghavPal
@RaghavPal 2 жыл бұрын
Hi Saira, I will check and update, Thanks for letting me know
Understanding Package-lock.Json | Javascript Tutorial
12:50
The Code Creative
Рет қаралды 8 М.
Cypress Complete Beginners Masterclass 1 | Step by Step | Raghav Pal |
1:20:54
Automation Step by Step
Рет қаралды 218 М.
Andro, ELMAN, TONI, MONA - Зари (Official Music Video)
2:50
RAAVA MUSIC
Рет қаралды 2 МЛН
ССЫЛКА НА ИГРУ В КОММЕНТАХ #shorts
0:36
Паша Осадчий
Рет қаралды 8 МЛН
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,3 МЛН
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 920 М.
Difference Between REST API vs Web API vs SOAP API Explained
7:24
Learn with Whiteboard
Рет қаралды 300 М.
I Spent 100 Hours Inside The Pyramids!
21:43
MrBeast
Рет қаралды 33 МЛН
package.json is not enough
15:40
Hussein Nasser
Рет қаралды 54 М.
What is NPM, and why do we need it? | Tutorial for beginners
14:27
Coder Coder
Рет қаралды 344 М.
package-lock.json explained
4:29
Bogdan Stashchuk
Рет қаралды 31 М.
Node.js Ultimate Beginner’s Guide in 7 Easy Steps
16:20
Fireship
Рет қаралды 1,8 МЛН
What is NPM's package-lock.json?
3:24
Tom Gregory
Рет қаралды 15 М.
Andro, ELMAN, TONI, MONA - Зари (Official Music Video)
2:50
RAAVA MUSIC
Рет қаралды 2 МЛН