This sample grunt file https://gruntjs.com/sample-gruntfile reads in a config object from package.json and stores it in the pkg property:
pkg: grunt.file.readJSON('package.json')
However, the page doesn't give a sample package.json file. Later on it refers to pkg.name. I assume this is a top level key in package.json. E.g.
{
"name": "this value here",
}
Is that correct?
Yes that's correct.
The package.json file is the heart of npm which is used by grunt.
You can generate one for your project using npm initand filling out the options or you can manually create and update it.
It gets updated automatically when using the --save option when adding modules to grunt.
npm install grunt-contrib-copy --save
This will install the module to your node_modules folder and update the dependencies section in your package.json
You only need to save the package.json file in your repo and each developer can download all dependencies listed in your package.json by calling npm install
Related
Does Webpack install -g, automatically install to nodeJS's package.json? Or is this only for local installs?
So I'm tired of trying to find workarounds for require() is not defined. Meaning I would need a module loader for my project to include modules client side. Well, I've downloaded the famous 'webpack' module loader, globally
npm install -g webpack
and I noticed it didn't install to "devDependencies" in my package.json file. But I also install webpack-dev-server, but locally,
npm install webpack-dev-server --save-dev
and it was saved into my package.json. Was this saved because I used --save-dev or because I installed locally?
I'm getting an error stating my webpack module I downloaded doesn't have a configuration file, so I'm assuming I install webpack wrong, and maybe it shouldn't have been installed globally. Please help with the understanding of globally and locally, as well as why this -g webpack install didnt get saved to the package.json?
The command npm install --gloabl will install a package in global scope and make it's bin command available to you globally. This has nothing to do with the folder or project your are in right now. That means a global install will not leave anything in any package.json files.
Learn more about npm install: https://docs.npmjs.com/cli/install
npm install -g webpack will save your files in your OS file system.
npm install webpack-dev-server --save-dev will save your package in your project directory inside a folder called node_modules.
The later one will make an entry in package.json file so that next time you can install all dependdencies with just npm install command. This command installs all your packages listed in package.json.
Missing Config file: Its looking for a file called webpack.config.js. More info can be found here: https://webpack.js.org/configuration/
I updated npm installed node express,even though it is not creating the jason file. can any one please let me know how to fix this.
ramesh#ramesh-PC MINGW32 ~
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.
See npm help json for definitive documentation on these fields
and exactly what they do.
Use npm install <pkg> --save afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (ramesh)
ramesh#ramesh-PC MINGW32 ~
First initialize your project. Assuming your project lives in directory "sample" then:
cd sample
npm init // This will ask a bunch of questions. you can mostly just hit "enter". it will create the package.json file for you
npm i express --save
using npm init you can create package.json
To clarify a bit on the previous answers, npm install <package-name> and npm install <package-name> --save may fail if you try to run them from a directory that does not have an npm package.json file.
You might type something like npm install crud --save and get some confusing output like this:
npm install crud
npm WARN saveError ENOENT: no such file or directory, open '/Users/youruser/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/youruser/package.json'
npm WARN youruser No description
npm WARN youruser No repository field.
npm WARN youruser No README data
npm WARN youruser No license field.
+ crud#0.0.28
That's not a very helpful error message -- the level is only "warn", and that last line makes it appear that the requested package got installed somewhere. But if you look in your directory, you will see it remains empty. The explanation of this "riddle" is that some package installers (like PHP's composer) will initialize a project and download the package, others (like Python's pip or npm) do not, so you have to initialize the directory and install packages separately.
Run npm init and answer some basic questions about your project, or copy a viable package.json file that follows the format below:
{
"name": "my-great-node-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
}
}
Be careful with the package name! The name cannot match the name of a package you trying to install.
Once the directory has been initialize, you should be able to run your npm install <package-name> --save command and have the package installed into the node_modules directory and have your package.json file updated.
Try not to make any space between words in your project folder name. For instance, instead of "My Portfolio" write it like "MyPortfolio". This worked for me and created json file automatically in my project folder.
I have multiple node modules developed by myself stored on a private gitlab server. In my Project, i install those modules with bower, so my Project structure Looks like this:
appname
bower_components
module1
...
package.json
module2
...
node_modules
...
package.json
When i call npm install only the dependencies from the package.json file located in the Folder "appname" will be installed. The Problem is, that my modules, which i install with bower, also have dependencies, which are not listed in the package.json in the root Folder. How can i install those dependencies without installing them globally? It should by something like npm install bower_components\module1. I also tried to use the command line Option --prefix but it only copies the Folder inside the node_modules Folder.
Thanks for your help
I am trying to install a Ionic 2 template.
Following the readme gets until the point where I need to install typings dependencies. After the installation of the typings CLI with npm install typings --global, I should install all the dependencies stated in the typings.json package (already provided by the template in the project folder).
This is how the typings.json file looks like:
{
"dependencies": {},
"devDependencies": {},
"ambientDependencies": {
"cordova": "registry:dt/cordova#0.0.0+20160316155526",
"cordova/plugins/statusbar": "registry:dt/cordova/plugins/statusbar#0.0.0+20160316155526",
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c"
}
}
As stated in the title, it gives me No dependencies as output and it doesn not install anything contained in that config file.
Could it be something related to having installed typings with sudo as a global package? Maybe it is looking for a config file in another directory?
Thanks!
This is most likely the update from 0.* to 1.*. Check the release notes
https://github.com/typings/typings/releases/tag/v1.0.0
Changes
Many breaking changes (see https://github.com/typings/core/releases/tag/v1.0.0)
Renamed ambient to global
Updated typings/ directory structure (removed browser.d.ts by default, should use typings/index.d.ts by default)
Killed defaultAmbientSource (no more auto-install of DefinitelyTyped when using --ambient, explicitly use dt~)
Replace ! parser expansion symbol with ~ (! is a reserved bash symbol)
Ability to specify different resolutions and output directories using resolution in typings.json
Using tslint-config-standard for linting rules
Fixing it for me was just replacing "devDependencies" with "globalDependencies" in my typings.json.
I had the same problem. I had to install node.js again (there was a newer version when I installed it again, 6.2.0) with the installer, node-sass with npm (I don't know if you need this one) and then the installation of typings worked.
I am using windows with node.js downloaded. I created this package.json.
{
"version": "0.0.0",
"name": "abc",
"devDependencies": {
"del": "^1.1.0",
"gulp-uglify": "^1.0.2",
"gulp-sourcemaps": "^1.2.8",
"gulp-typescript": "^2.3.0",
"less-plugin-clean-css": "^1.2.0",
"typescript": "^1.3.0"
}
}
Is there an npm command line task that I can run to fetch all of these modules and install / update these into a node_modules directory? If needed I can change my package.json so I would appreciate advice on that also.
Thanks
Doesn't
"npm install"
do the trick? (from your folder that contains the package.json)
It works on linux, haven't a window machine to try right now
try
npm install
npm update --save-dev
If you already had the package.json file (with dependencies entries), then you can use npm install to install dependencies on node_modules directory.
npm install
or you can update the dependencies to use latest version (will override currently installed dependencies on node_modules directory) using npm update
npm update
You don't have to put the dependency you want manually to package.json, you just use command npm install {package-name} with additional option like --save / --save-dev / --save-optional.
In example you want to add dependency of node-q to your application, you can do this:
npm install q --save
Juggling into different option --save-prefixed value will act as follows,
--save will add dependency to dependencies attribute of your package.json, it will be installed mainly for your application
--save-dev will add dependency to devDependencies attribute of your package.json, it will be installed for development phase of your application (usually it is testing dependencies)
--save-optional will installed for optional (nice to have) dependencies. I rarely used it for my applications or libraries anyway.
Don't forget you MUST run commands from your application directory (the one that node_modules directory resides).