Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js project with no package.json

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

like image 705
guagay_wk Avatar asked Nov 04 '15 09:11

guagay_wk


People also ask

Does node js need package json?

The package. json file is the heart of any Node project. It records important metadata about a project which is required before publishing to NPM, and also defines functional attributes of a project that npm uses to install dependencies, run scripts, and identify the entry point to our package.

Do I need to install NPM packages for every project?

1 Answer. Show activity on this post. NPM is extremely useful, but, when you install it, you install it globally. It comes with Node JS, so when you install Node JS, you should have npm installed(type npm -v to see the version and whether npm is installed).

Does npm install create package json?

Creating a package. json file is typically the first step in a Node project, and you need one to install dependencies in npm. If you're starting a project from scratch, you create a package. json file to hold important metadata about your project and record your dependencies.

CAN Node run without npm?

Yes, it is possible to develop a Node. js application with no NPM registry binaries. This guide aims to give an overview on how to use pure Node. js and its functionalities.


2 Answers

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 installed so many things that your project grows beyond 4TB size.

There is no data storage device available to shit 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.

like image 89
AdityaParab Avatar answered Sep 23 '22 21:09

AdityaParab


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.

like image 38
XCS Avatar answered Sep 20 '22 21:09

XCS