Specifying a required Node.js version in Package.json file
In this post we will give you information about Specifying a required Node.js version in Package.json file. Hear we will give you detail about Specifying a required Node.js version in Package.json fileAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to specify a required node version inside your package.json file.
If we specify the required node.js version in package.json file npm will notify the users that our project only runs on a particular node version.
Specifying the Node version
-
Open the node project in your favorite code editor.
-
Navigate to the package.json file and add the following engines field by replacing it with your required node version.
"engines": { "node": ">=12"},
Here I set a node version >=12 so that my project only works on node version 12 and above.
- Create a .npmrc file in your project root folder and the following config.
engine-strict=true
This will give an error to the user if he or she uses different node versions (other than specified).
npm ERR! code ENOTSUPnpm ERR! notsup Unsupported engine for node-app@1.0.0:wanted: {"node":">=8"} (current: {"node":"10.14.1","npm":"6.13.4"})npm ERR! notsup Not compatible with your version of node/npm: node-app@1.0.0npm ERR! notsup Not compatible with your version of node/npm: node-app@1.0.0npm ERR! notsup Required: {"node":">=12"}npm ERR! notsup Actual: {"npm":"6.13.4","node":"10.14.1"}npm ERR! A complete log of this run can be found in:
Hope this code and post will helped you for implement Specifying a required Node.js version in Package.json file. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs