没有 package.json 的 Node.js 项目 [英] Node.js project with no package.json
问题描述
有一个没有 package.json 的 node.js 项目可以吗?我在网上看到的都是 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
没有package.json有什么影响?
What is the effect of having no package.json?
package.json 最初是如何创建的?它是自动创建的吗?我想知道为什么我没有 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
推荐答案
从根本上说,package.json
是应用程序的元文件.它列出了应用程序的所有配置.
Fundamentally, package.json
is a meta file for your application. It lists all the configuration of your application.
没有package.json有什么影响?
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.
让我们设置一个场景让您更好地理解这一点.想象一下,您使用 node 编写了一个出色的应用程序.现在你周围的所有小鸡都想和它一起玩.太棒了!现在您想将其提供给他们,并且在开发过程中您npm install
做了很多事情,以至于您的项目大小超过了 4TB.
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 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.
在那里你偶然发现了一个叫做 package.json
的神奇东西.
That is where you stumble upon a magical thing called package.json
.
因此,您要做的是在 dependencies
属性下列出所有 npm install
ed 模块.然后删除 node_modules
文件夹,添加 package.json
并在 github 中提交整个该死的东西.甚至 .zip
文件也是 10MB
So what you do is you list all your npm install
ed modules under dependencies
property. Then you delete node_modules
folder, add package.json
and commit the entire damn thing in github. Even the .zip
file is of 10MB
然后她得到了密码.在 npm install && 中输入npm start
(这将安装 package.json` 中的所有依赖项并启动您的应用程序)
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)
但是,如果您有 package.json,则可以在此处指定所有依赖项.
If you have package.json however, that is where you specify all your dependencies.
使用 npm install
示例.
npm install express --save
package.json 最初是如何创建的?是自动创建的吗?
How is package.json created in the first place? Is it created automatically?
您可以手动创建一个文本文件并将其保存为 package.json
You can manually create a text file and save it as package.json
或
更复杂的方法是使用命令
A more sophisticated way is to use the command
npm 初始化
我想知道为什么我没有 package.json
I am wondering why I do not have package.json
我也是!:)
您很可能正在学习一个不强调项目初始配置的教程,或者这些教程的作者假定读者已经掌握了所有基础知识.
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.
这篇关于没有 package.json 的 Node.js 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!