Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Recently I started learning typescript and little new to NPM, wants know about why npm init is used. can anyone please explain real time example. and most importantly please don't say question is asked here, there i am not satisfied with those answers so i am asking again here.
$ npm init
Npm is package manager with npm repository (here you can search pacakges https://www.npmjs.com/). If you need to install anything you need package.json file, that is created by npm init (the packages are used so you don't need to write code that someone else was already written), You can write that file yourself and not need to call npm init. The package.json is needed when you still packages because npm write installed packages into that file (I think that if you call npm install it will also create that file). So you can use npm install on directory that don't have packages installed (no node_modules directory) and it will install them, that way you can share you project and don't need to share lot of files from packages only one file is needed and of course code for you app. This is especially importent if you use lot of packages.
npm init can convert an empty directory to an npm project by adding package.json into it.
Also, you can add meta info of the project to the package.json while creating it.
If you don't have package.json in a directory, and you trigger npm install moduleName at that directory path then module will be installed globally
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have 'request' npm package which is deprecated and being installed by another npm package as a dependency. Now I would like to update the dependencies of request package. I tried every possible way but, didn't find the solution.
Here's the dependency tree which i have to update the last one i.e. uuid:
`-- protractor#7.0.0
`-- webdriver-manager#12.1.8
`-- request#2.88.2
`-- uuid#3.4.0
NPM packages are built to work with a certain version (or version set) of their dependencies. If you update uuid to a later version, you might run into unexpected issues with request. Updating a dependency of one of your dependencies explicitly is not supported or recommended therefore.
Is it ok to have a node.js project with no package.json? The ones I see on the internet all come with package.json
What is the effect of having no package.json?
How is package.json created in the first place? Is it created automatically? I am wondering why I do not have package.json
Fundamentally, package.json is a meta file for your application. It lists all the configuration of your application.
What is the effect of having no package.json?
Nothing as far as you're running all your code locally and have no requirement for deployment whatsoever.
Let's setup a scene for you to understand this better.
Imagine that you wrote a brilliant application using node. Now all the chicks in your surrounding want it to play with. It is so fantastic!
Now you want to give it to them and during the development process you `npm install`ed so many things that your project grows beyond 4TB size.
There is no data storage device available to ship that huge code base.
Then the girl of your dream said I want it and I want it now. So you begin searching for app deployment process for node applications.
That is where you stumble upon a magical thing called package.json.
So what you do is you list all your npm installed modules under dependencies property. Then you delete node_modulesfolder, add package.json and commit the entire damn thing in github. Even the .zip file is of 10MB
Then she gets the code.
Types in npm install && npm start (which will install all the dependencies from the package.json` and start your application)
If you have package.json however, that is where you specify all your dependencies.
Using --save flag of npm install
Example.
npm install express --save
How is package.json created in the first place? Is it created automatically?
You can manually create a text file and save it as package.json
OR
A more sophisticated way is to use the command
npm init
I am wondering why I do not have package.json
Me too! :)
You're most probably following a tutorial that doesn't emphasize on initial configuration of the project OR the author of those tutorials presume that the reader has all the fundamentals down to begin with.
It is created automatically if you write npm init.
Then, every package you add using npm install packagename --save will be added to the dependencies list.
You need package.json so that when you want to use your project on another machine you don't have to copy all node_modules, but only your .js files you have written, assets and package.json. You can then run npm install command and it will automatically download and install all the required modules (found in the list of dependencies inside package.json).
You can also manually create or edit it, but it's easier to add --save when installing a module so you don't have to worry about package versions and stuff like that.
Also if you want to create a npm package, an open source project or stuff other people will use, it's either required or the norm to have this package.json file describing your project.
package.json is npm file, if you don't use npm you will not have this file, npm is a great tool if you want to use external libraries in your project but if you don't need it (which is very not likely unless you are doing something very simple), you don't need package.json file too.
To generate package.json file initialize npm in your project using npm init
possible reason thus it exist is you maybe you enter a wrong command like npm i -y, you must initialize the project first, just enter a command npm init -y
Welcome.
Well, if you are running it on your local machine, it's fine. now to answer your last question, package.json is not created automatically.
the npm command npm init -y creates the 'package.json' file. It basically makes sharing your code and installing your codebase easier.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Following this tutorial on 'context menu's' in d3:
'https://github.com/patorjk/d3-context-menu'
It says to install with Bower. Now I googled it and followed this tutorial :
'http://blog.teamtreehouse.com/getting-started-bower'
So installed Node.js and now I'm stuck. Where do I put the bower install d3-context-menu found in the first tutorial ?
And what is Bower ?
Bower is a package manager that downloads some web libraries to your host.
Where do I put bower install d3-context-menu found in the first tutorial ?
In command prompt.
But firstly you need to install bower by
npm install bower
npm is node.js package manager (that installs node.js modules).
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am interested to learn about the Node.js framework Sails.js. But I want to know how to install it. I want to know how to install it every operating system.
I haven't found any exe version to install it or is there any other way to install it ?
Suggest me how to do it.
Hoping that you have Node.js installed in your system, you can use this command to install Sails:
sudo npm -g install sails
To verify you SailsJS installation use this command:
sails -v
You can follow this helpful tutorial on this: How to install Sails.js
In my project I've installed bower components without save option. Now, I would like update to bower.json?
How can I update bower.json with installed packages?
Just list your dependencies:
bower list
Then you should run all install command with param '--save' like this:
bower install bootstrap --save
It's a hard work, but if you have a thousand dependencies, could you create a script to automatize the task.
A little trick if you don't want to write a script for that:
before doing anything rename your bower.json in bower2.json for example.
then you can do a:
$ bower init
(automatically create a bower.json file).
note that all questions should be pre-filled with your current config.
When it will ask you:
set currently installed components as dependencies?
say yes,
You now have all your dependencies in the new bower.json file (and you can check if everything is right with the old bower2.json)
A bit arduous way is to run bower list, look for packages labeled extraneous and add those manually to the dependencies in the bower.json.
If there are a lot of extraneous packages, it might be easier to workaround this by running bower init and answering Yes to "set currently installed components as dependencies?". This will take your current bower.json, read it and then create new one using information from the old one. So in an ideal case you will have the same file just with extraneous packages added.
Warning: Firstly, there might be something lost in the process (e.g. devDependecies). Secondly in the last version of bower (v1.2.7) this will not preserve current packages info! I feel it is a bug. However you can save the old file and (manually) merge it with the generated one.
Also, you should ask for an option or something by opening a bower issue as this would be welcomed by many developers.
You can use bower-check-updates (you need installed node.js on your machine):
bower-check-updates is a utility that automatically adjusts a bower.json with the latest version of all dependencies
bower-check-updates - is a fork of npm-check-updates, so it's all the same but updates bower.json, instead of package.json
npm install -g bower-check-updates
bower-check-updates -u
bower install
This will install bower-check-updates globally, so you can launch it from anywhere.
P.S. for more information about npm-check-updates pleas see this topic
If there aren't that many bower packages you have installed, try writing bower install [package_name] --save. This will just update your bower.json file.
After bower-check-updates -u you must run bower install instead of npm install