可以在流星应用程序中使用 nodejs 包吗? [英] it possible use a nodejs package inside meteor app?

查看:30
本文介绍了可以在流星应用程序中使用 nodejs 包吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在服务器端的流星应用程序中使用 nodejs 包吗?这样做会很棒,因为 nodejs 有大量的包.

it posible use a nodejs package inside meteor app on server side? It would be great to do that since nodejs has a large number of packages.

推荐答案

是的,这是可能的.您可以在 Meteor 中使用 npm 模块,因为它基于 Node.js.

Yes, it is possible. You can use an npm module in Meteor, since it's based on Node.js.

这段代码对我很有效,例如:

This code has worked for me fine, e.g.:

var fs = __meteor_bootstrap__.require('fs');

更新:在 Meteor 应用中安装 npm 模块

  1. 在终端中,更改 Meteor 应用程序目录的路径.
  2. <代码>>cd .meteor/local/build/server
  3. 像这样安装一个 npm 模块 >npm install module_name.

 

 

对于访问此帖子的任何人来说,它已过时.从 Meteor 0.6.4 开始,您使用 Npm.require 而不是 __meteor_bootstrap__.require:

for anyone visiting this post, it is outdated. As of Meteor 0.6.4, you use Npm.require instead of __meteor_bootstrap__.require:

var fs = Npm.require('fs');

此外,如果您不使用标准节点包,而是使用 npm 存储库中的一个,最好创建一个依赖项,以便在您每次创建项目的新实例时自动安装它.为此,请使用以下行创建 /packages/someName/package.js 文件:

Also, if you don't use standard node package, but one from npm repositories, it's better to create a dependency so that it's automatically installed every time you create a new instance of the project. To do so, create a /packages/someName/package.js file with the following line:

Npm.depends({'packageName': 'packageVersion'});

这篇关于可以在流星应用程序中使用 nodejs 包吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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