Why do we need to use package.json? [duplicate] - javascript

This question already has answers here:
What are the main uses for the NPM package.json file?
(2 answers)
Closed 6 years ago.
I am trying to learn web socket with JavaScript to this site, but I do not understand something that why I need to use package.json. This is my package.json file code:
`{
"name": "module-name",
"version": "10.3.1",
"description": "An example module to illustrate the usage of a package.json",
"author": "Your Name <you.name#example.org>",
"contributors": [{
"name": "Foo Bar",
"email": "foo.bar#example.com"
}],
"bin": {
"module-name": "./bin/module-name"
},
"scripts": {
"test": "vows --spec --isolate",
"start": "node index.js",
"predeploy": "echo im about to deploy",
"postdeploy": "echo ive deployed",
"prepublish": "coffee --bare --compile --output lib/foo src/foo/*.coffee"
},
"main": "lib/foo.js",
"repository": {
"type": "git",
"url": "https://github.com/nodejitsu/browsenpm.org"
},
"bugs": {
"url": "https://github.com/nodejitsu/browsenpm.org/issues"
},
"keywords": [
"nodejitsu",
"example",
"browsenpm"
],
"dependencies": {
"primus": "*",
"async": "~0.8.0",
"express": "4.2.x",
"winston": "git://github.com/flatiron/winston#master",
"bigpipe": "bigpipe/pagelet",
"plates": "https://github.com/flatiron/plates/tarball/master"
},
"devDependencies": {
"vows": "^0.7.0",
"assume": "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0",
"pre-commit": "*"
},
"preferGlobal": true,
"private": true,
"publishConfig": {
"registry": "https://your-private-hosted-npm.registry.nodejitsu.com"
},
"subdomain": "foobar",
"analyze": true,
"license": "MIT"
}`
But I do not understand why I need to use it. I tried to find on google but can not find something useful. One more thing, if I create package.json then why I need to write dependencies?

You do not NEED package.json. However, you will most likely want it. As you make larger applications using node.js, you will find that using other people's code is the best solution vs. writing the same thing yourself.
npm has lots of packages that people want to use over and over again. package.json provides a simple way for people to keep track of packages they use in their application.

Related

Why can I no longer minify my Javascript files?

I am using VS Code to maintain a Javascript library I created and I used Google Closure Compiler (CC) to minify the js file. I have made some changes to the original code but although CC executes without any warning/error messages it fails to create the output file.
This is the package.json file
{
"name": "canvas-gui",
"version": "1.0.0",
"description": "On canvas GUI for p5.js",
"main": "main.js",
"scripts": {
"tsc": "tsc",
"typedoc": "npx typedoc",
"gcc": "npx google-closure-compiler src_js --js_output_file dist/lib/gui.min.js --language_in ECMASCRIPT_2020 --language_out ECMASCRIPT_NEXT"
},
"keywords": [
"GUI",
"canvas",
"p5.js"
],
"author": "Peter Lager",
"license": "MIT",
"devDependencies": {
"#types/p5": "^1.4.2",
"google-closure-compiler": "^20220803.0.0",
"p5": "^1.4.2",
"typedoc": "^0.23.10",
"typescript": "^4.7.4"
}
}
I researched on the parameter values here and tried changing the source parameter to
--js src/**.js
--js='src_js/**.js'
src_js/canvas_gui.js
--js src_js/canvas_gui.js
--js='src_js/canvas_gui.js'
all without success.
I also set the warning level to VERBOSE but still no messages.

Server running error in parcel by starting the external file index.html I Ignoring the main but it also doesn't work(Build Failed)

[Build Error in parcel # 2.7.0 start when I am trying to add external index.html file in the main I also ignored the main but it also doesn't work for me. Will please someone help me to solve this problem It also not working with JavaScript file when I added externally and also getting error with html file but I want to add the html file but as a solution I try to add JavaScript file but it also doesn't work for me. Will please someone solve this issue or tell me how to solve this issue
{
"name": "forkify",
"version": "1.0.0",
"description": "",
"main": "unrelated.js",
"targets": {
"main": false
},
"scripts": {
"start": "parcel start index.html",
"build": "parcel build index.html"
},
"author": "Meelad Sultan",
"license": "ISC",
"devDependencies": {
"parcel": "^2.7.0"
}
}
enter code here
At last I can find the solution of my problem after almost a day if someone else facing the same problem they just do add the **Browsers list ** in the package.json file before script and ignore the main target and also set the parcel to latest then the parcel will run successfully and do not give any server error or build error. And don't forget to run periodically npx browerlist#latest --update-db. It will update your package-lock file with new caniuse-lite version. In this case, you will be sure that last two version or > 0.2% will target what you expect
{
"name": "forkify",
"version": "1.0.0",
"description": "",
"main": "unrelated.js",
"target": {
"main": false
},
"browserslist": "> 0.5%, last 2 versions, not dead",
"scripts": {
"start": "parcel index.html "
},
"author": "Meelad Sultan",
"license": "ISC",
"devDependencies": {
"#parcel/transformer-sass": "^2.7.0",
"parcel": "latest"
},
"dependencies": {
"sass": "^1.55.0"
}
}

I can put a few more things in the package.json?

this is my package:
{
"name": "any name :D",
"version": "3.2.0",
"nameVersion": "",
"descriptionVersion": "",
"engines": {
"node": "14.15.0"
},
"description": ":D",
"main": "src/index.js",
"scripts": {
"start": "node ."
},
"author": "",
"license": "",
"dependencies": {
"discord.js": "^12.5.1",
"express": "^4.17.1"
}
}
as you can see, there are two more keys, nameVersion & descriptionVersion.. I thought it would be nice to leave them with the version, which comes with it when I put npm init..
But a question came to me, is there a problem if I put something that is normally npm? like, even if no error, is it a bad practice? Or am I just traveling? well, i tested it and it works fine, but i'm still thoughtful about it..
It's probably okay to have additional properties, although it would probably be good to have any additional properties grouped together under a single key. Many JS libraries also use additional properties for example ESLint uses "eslintConfig", etc. in package.json: https://eslint.org/docs/user-guide/configuring#using-eslintignore-in-packagejson

Error - git push heroku master

If you're attempting to help me, I really appreciate it.
So when I write git push heroku master, it fails to parse, and before you spit at me and say 'READ OTHERS!!!!' I have. I've rewritten the package.JSON and used a validator. The strange thing is it always says line 9, column 3, every time I reformat the package.JSON, always line 9, column 3. I have changed over 5-7 times. I don't think my package.json is necessary as it always brings that error.
But here it is anyway.
{
"name": "vulture",
"version": "1.0.1",
"description": "Vulture is a bot for discord.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"engines": {
"node": "8.4.0",
"npm": "5.4.0"
},
"author": "swagehsaan840#0336",
"license": "MIT"
}
A side note is changing it will probably give me the same error, but I never know, after using a validator and changing any times, it always says line 9, column 3.
Thanks anyway! :)
try to write this way package.json
{
"name": "vulture",
"version": "1.0.0",
"description": "vulture",
"main": "index.js",
"private": true,
"scripts": {
"start": "node index.js",
},
"author": "vulture",
"license": "ISC",
"dependencies": {
"node": "8.4.0",
"npm": "5.4.0"
}
}
add Buildpacks in heroku goto setting select add Buildpacks --> select nodejs

node_modules is not recognized as an internal or external command

I'm trying to write a test automation script using appium, jasmine, and perfecto mobile. I'm using the project cloned from the following URL with my own configuration Appium Javascript Example
The problem is when I execute the npm test command I get the following error
node_modules is not recognized as an internal or external command
This is how the packages.json script looks like:
{
"name": "perfecto_appium_sample",
"version": "1.0.0",
"description": "The following sample shows how to Install an application and use WebDriverIO to automate and test it.<br/> It uses selendroid test application which can be downloaded from [here](https://github.com/PerfectoCode/AppsForSamples/tree/master/selendroid-test-app-0.17.0).",
"main": "perfectoSpec.js",
"scripts": {
"test": "node_modules/webdriverio/bin/wdio wdio.conf.js",
"start": "wdio wdio.conf.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"wdio": "^0.3.3",
"wdio-jasmine-framework": "^0.2.19",
"wdio-mocha-framework": "^0.5.12"
},
"dependencies": {
"wd": "^1.5.0",
"webdriverio": "^4.10.2"
},
"keywords": []
}
you need to provide relative path properly:
"scripts": {
"test": "node ./node_modules/webdriverio/bin/wdio wdio.conf.js",
"start": "wdio wdio.conf.js"
}
Just remove the paths "node_modules/webdriverio/bin/" and simply specify "wdio wdio.conf.js". It should work.

Categories

Resources