Node.js是package.json的主要参数 [英] Node.js package.json main parameter

查看:316
本文介绍了Node.js是package.json的主要参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了很多搜索。但是,仍然怀疑Node.js的package.json中的主要参数。

I have done quite some search already. However, still having doubts about the main parameter in package.json of Node.js.


  1. 如何填写此字段有帮助?以另一种方式询问,如果此字段显示,我可以以不同的样式启动模块吗?

  2. 我可以在主参数中填入多个脚本吗?如果是的话,他们会以两个线程开始吗?如果不是,我如何在模块中启动两个脚本并让它们并行运行?

我知道第二个问题是相当的奇怪的。这是因为我在OpenShift上托管了一个Node.js应用程序,但该应用程序由两个主要组件组成。一个是REST API,另一个是提供服务的通知。

I know that the second question is quite weird. It is because I have hosted a Node.js application on OpenShift but the application consists of two main components. One being a REST API and one being a notification delivering service.

我担心如果将REST API实现为单个线程,通知传递过程将阻止REST API。但是,他们必须连接到相同的MongoDB盒式磁带。此外,如果可能的话,如果两个部件都可以使用相同的装备,我想保存一个装备。

I afraid that the notification delivering process would block the REST API if they were implemented as a single thread. However, they have to connect to the same MongoDB cartridge. Moreover, I would like to save one gear if both the components could be serving in the same gear if possible.

欢迎任何建议。

推荐答案

来自 npm文档


主要字段是模块ID,它是
程序的主要入口点。也就是说,如果你的软件包名为foo,并且用户安装
it,然后执行require(foo),那么将返回主模块的导出
对象。

The main field is a module ID that is the primary entry point to your program. That is, if your package is named foo, and a user installs it, and then does require("foo"), then your main module's exports object will be returned.

这应该是相对于包
文件夹根目录的模块ID。

This should be a module ID relative to the root of your package folder.

对于大多数模块,它会使最有意义的是有一个主脚本和
通常不是很多。

For most modules, it makes the most sense to have a main script and often not much else.

简而言之:


  1. 您只需要 package.json main 参数c $ c>如果您的包的入口点与其根文件夹中的 index.js 不同。例如,人们经常把入口点放到 lib / index.js lib /< packagename> .js ,在这种情况下,相应的脚本必须在 package.json 中描述为 main

  2. 你不能有两个脚本 main ,只是因为入口点 require('yourpackagename')必须明确定义。

  1. You only need a main parameter in your package.json if the entry point to your package differs from index.js in its root folder. For example, people often put the entry point to lib/index.js or lib/<packagename>.js, in this case the corresponding script must be described as main in package.json.
  2. You can't have two scripts as main, simply because the entry point require('yourpackagename') must be defined unambiguously.

这篇关于Node.js是package.json的主要参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆