Tag: 节点模块

在AngularJS应用程序中使用node_modules

我刚刚使用Yeoman项目生成器工具生成了一个angular度应用程序。 生成的项目有一个目录“node_modules”。 在这个模块里面有很多可能为array-diff等“预定义的函数”,而且我想在angularJS应用程序(控制器,指令)中使用这些函数。 我尝试过使用RequireJS和Node-Browserfy来使用这些node_modules,但没有成功,每次出现错误。 例如“filter不defiend等…”。 有没有一步一步的教程做这个模块集成到一个AngularJS应用程序? 我的项目结构是: 这是我的node.browswerfy生成的bundle.js (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ var myFilter =require('../../node_modules/array-filter/index.js'); },{"../../node_modules/array-filter/index.js":2}],2:[function(require,module,exports){ /** * Array#filter. * * @param {Array} arr * @param {Function} fn * @return {Array} */ module.exports = function (arr, fn) { […]

运行sonarqube分析我的代码时得到NullPointerException

我有一个Jenkins的工作来发布unit testing覆盖(lcov格式)到SonarQube服务器,如问题及其答案中所述。 有时,我在Jenkins控制台日志的node_modules目录中看到以下JavaScript文件exception。 16:57:15.037 ERROR – Problem while calculating coverage for /var/lib/jenkins/jobs/jenkins-project-name/workspace/project-name/node_modules/js-tokens/test/fixtures/regex.js java.lang.NullPointerException: null at org.sonar.plugins.javascript.lcov.UTCoverageSensor.saveZeroValueForResource(UTCoverageSensor.java:146) [sonar-javascript-plugin-2.9.jar:na] at org.sonar.plugins.javascript.lcov.UTCoverageSensor.saveMeasureFromLCOVFile(UTCoverageSensor.java:128) [sonar-javascript-plugin-2.9.jar:na] at org.sonar.plugins.javascript.lcov.UTCoverageSensor.analyse(UTCoverageSensor.java:85) [sonar-javascript-plugin-2.9.jar:na] at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58) [sonar-batch-shaded-5.2.jar:na] at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50) [sonar-batch-shaded-5.2.jar:na] at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:98) [sonar-batch-shaded-5.2.jar:na] at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192) [sonar-batch-shaded-5.2.jar:na] at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:100) [sonar-batch-shaded-5.2.jar:na] at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:85) [sonar-batch-shaded-5.2.jar:na] at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:258) [sonar-batch-shaded-5.2.jar:na] at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:253) [sonar-batch-shaded-5.2.jar:na] at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:243) [sonar-batch-shaded-5.2.jar:na] at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:100) [sonar-batch-shaded-5.2.jar:na] at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:85) […]

在模块中使用npm3无法获取父节点模块

不知道这是npm3一个已知问题,但由于npm3的扁平模块结构,从一个模块内,我不能findnode_modules使用, var node_modules = fs.readdirSync('node_modules'); 相反,我必须使用, var node_modules = fs.readdirSync('../../node_modules'); 遍历find它。 由于node_modules嵌套在包中,这显然不会发生在npm2 +上。 有没有解决的办法 ? 我search了每一个更好的解决scheme。

JavaScript ES6模块OnLoad处理程序实现

我有一个NodeJS服务器应用程序被分割成ES6模块丢失。 我正在尝试创build一种“加载模块处理程序”,这是主模块中的一个函数,其他模块需要注册一个callback函数,在主模块完全初始化后执行。 我使用Babel(带有babel-preset-es2015 )将ES6模块转换为可执行的JavaScript。 为了演示这个问题简而言之,我创build了2个示例文件。 文件index.js (应用程序条目,主要模块): import * as js2 from "./js2.js"; let toCall = [], // this array handles callbacks from other modules initialized = false; // flag export function onInit (cb) { // registers cb to execute after this module is initialized if (initialized) { cb(); return; } toCall.push(cb); } function done […]

在节点js中使用缓冲区会导致内存泄漏

我读“节点js中的缓冲区对象是在v8堆外创build的” 这是真的? 如果是的话,它会在正常的GC循环中收集垃圾?

build立模块时,我们应该在哪里保存演示应用程序依赖关系?

我正在构build我的第一个节点模块。 模块内部有一个演示应用程序。 该演示仅在开发过程中有用。 我们在哪里放演示的依赖关系? 想到的第一个答案是把它们放到devDependencies ,因为它们只在开发过程中有用。 这就是说,通常我保留devDependencies的构build工具,而不是运行(演示)应用程序的模块。 所以问题是,当开发一个包含自己的演示应用程序的模块时,在哪里放置演示应用程序的依赖关系? dependencies ? devDependencies ? someWhereElse ? 这是模块: https : //github.com/shaunluttin/aurelia-open-id-connect 这里是我的模块中的依赖关系的高级图。 ()中的位置基于Pranesh的答案。 demo third-party-modules (optionalDependencies) my-module third-party-modules (dependencies) 当有人安装我们的模块,我们希望他们只能拉下my-module/third-party-modules 。 当有人克隆我们的回购,我们希望他们最好能够拉下demo/third-party-modules 。

获取该模块正在运行的__dirname?

有没有一种方式,我的模块可以得到它正在运行一个函数文件的__dirname ? 就像是: module.js module.exports.dir = function(){ console.log(__dirname); } file.js var module = require("./module.js"); module.dir(); // /home/user/dir/file.js instead of /home/user/dir/module.js

NodeJS服务器端应用程序部署的协调

我正在用Angular写一个nodejs应用程序作为我的前端。 为此我有Git作为我的代码pipe理服务器。 对于客户来说,我正在进行缩小,并准备好生产。 但是我不确定,如何准备服务器端文件进行生产。 我们是否需要将所有Git文件夹复制到生产服务器? 让我知道部署nodejs服务器应用程序的最佳方法。

意外的input错误结束,这是第一次使用DiskDB

我正在研究节点js应用程序并使用Diskdb作为数据库。 它第一次发生错误如下: undefined:0 ^ SyntaxError: Unexpected end of input 在文档中,我发现这个解决scheme是“请确保它包含一个有效的JSON数组,否则, diskDB将返回一个空的数组”。 那么可以任何一个build议我如何检查这个文件包含json数组或不? 我正在使用加载收集 db.loadCollections(['users']); var u = db.users.findOne(); console.log(u); // [] 我如何检查[]是否存在或不存在? 还有一个问题是我该如何testinglogging是否存在或不在diskdb中的多个条件。 例如在users.json中包含 [{"email":"noname@email.com","password":"123","status":"1","_id":"e39a62a9c7b94d76892f9c3bdfa22715"}] 和我使用的代码,我正在检查如下: db.loadCollections(['users']); var preCheck = db.users.find({"email" : req.body.email,"password" : req.body.password}); if(preCheck !== undefined){ if( (preCheck.email == req.body.email) && (preCheck.password == req.body.password) ){ //logged in req.session.email = req.body.email; req.session.userId = preCheck._id; […]

如何使用Node.js获取Windows版本?

有关于堆栈溢出操作系统版本的问题,但不是关于Windows名称,我正在寻找使用Node.js找出Windows名称。 我研究了os , platform , getos和using process等很多模块,发现这些模块对于获取操作系统描述,进程环境等都有帮助。我能够得到它是Linux还是Windows,也就是说我是哪个平台使用。 但是,我怎样才能检查,是我的系统上使用Node.js安装的Windows 7或8? 我在我的Node.js项目中使用kinect2模块,它在Windows 8上工作正常,但我期待在Windows 7上使用它。 我已经检查过,Kinect2不能在Windows 7上运行。