testing蓝鸟承诺与Nodejs誓言(BDD)

我遇到了一些问题,比如如何正确构build我的Promise返回API的testing topic:function() { return myfunc() { /* returns a Bluebird Promise */ } }, 'this should keep its promise':function(topic) { var myfunc = topic; myfunc() .then(function(result) { assert(false); }) .catch(function(error) { assert(false); }) .done(); } 我的誓言永远不会失败。 这是我第一次尝试使用誓言来testing承诺。 希望有人熟悉这一点会伸出援助之手。 提前,谢谢。 恩里克

我试着用'temp'和'fs'模块来使用browserify,我得到的只是这个糟糕的错误

我正在尝试迁移节点项目以在浏览器中运行。 该项目(从来不知道这一刻的原因)写入临时文件,使用临时代码类似于这样的代码: var temp = require('temp'); var fs = require('fs'); temp.open('helloworld.txt', function (err, info) { if (err) { console.log('Failed to open a temp file:', err); return; } console.log('temp: ', info.path); fs.writeFile(info.path, 'Hello World!', function (err2) { if (err2) { console.log('Failed to write to a temp file:', err2); return; } }); }); 当运行browserified代码时,我得到以下错误: Uncaught TypeError:undefined不是一个函数 对于以下行: […]

MongoDB使用Node.js获取集合中文档的数量(计数)

我目前正在写一个函数,应该返回一个集合文件的数量,当我返回的值说undefined,这是我的代码: var MongoClient = require('mongodb').MongoClient; // open the connection the DB server var dbName = "ystocks"; var port = "27017"; var host = "localhost"; var tt = "mongodb://" + host + ":" + port + "/" + dbName; //"mongodb://localhost:27017/ystocks" function getNumOfDocs (collectionName, host, port, dbName) { var tt = "mongodb://" + host + ":" + […]

Azure表存储性能

我应该以多快的速度期待Azure存储的性能? 我在getEntity,updateEntity等基本操作上看到〜100ms。 这家伙似乎正在得到4ms,这使得这里看起来真的是错了! http://www.troyhunt.com/2013/12/working-with-154-million-records-on.html 我正在使用azure-table-node npm插件。 https://www.npmjs.org/package/azure-table-node 一个简单的getEntity调用需要~90ms: exports.get = function(table, pk, rk, callback) { var start = process.hrtime(); client().getEntity(table, pk, rk, function(err, entity) { console.log(prettyhr(process.hrtime(start))); … azure色的存储模块似乎更慢: https://www.npmjs.org/package/azure-storage var start = process.hrtime(); azureClient.retrieveEntity(table, pk, rk, function(err, entity) { console.log('retrieveEntity',prettyhr(process.hrtime(start))); … retrieveEntity 174 ms

Metalsmith.js:如何构build到与构build脚本相同的目录?

我对Metalsmith完全陌生。 我一直在关注这个教程: http : //www.robinthrift.com/posts/metalsmith-part-1-setting-up-the-forge/ 我想build立我的网站到我的项目的根目录(与生成脚本相同的目录)。 我想要做到这一点,因为我希望github页面可以很好地播放它。 但是当我尝试构build时,我得到这个错误:错误:EBUSY,资源忙或locking 这是我的dir结构: project_folder / _site-SRC / 的index.html node_modules build.js 的package.json 这里是我的build.js源代码: var Metalsmith = require("metalsmith"); Metalsmith(__dirname) .source("_site_src") .destination(".") .build(); 我想让我的项目目录看起来像: project_folder / _site-SRC / 的index.html node_modules build.js 的package.json 的index.html 我不知道我在做什么错。 我感谢任何帮助。

nodejs – 如何更改文件的创build时间

fsStat类实例返回mtime,atime和ctimedate对象,但似乎只有API才能更改mtime和atime(最后修改和访问我猜)。 我如何更改创build时间来创build文件的精确副本,因为它也会创build与原始副本相同的时间?

Nodejs – 写入和保存文件

我正在调查如何将文件下载到用户的本地机器,但我不太清楚为了做到这一点,我需要什么。 我在前端使用Nodejs和Express与Angularjs。 用户可以将文本写入文本区域,这是将文本写入文件。 要做到这一点,我有: … fs = require('fs'); fs.writeFile('filename.txt', textarea.text, function (err) { if (err) return console.log(err); res.send(200); }); … 一旦文件被创build,我怎么得到它在用户的机器上下载?

HTTP POST在节点红js

我想知道如何做一个带有JSON数据的HTTP POST请求到带有API密钥的服务器。 我在http://nodered.org/docs/search,但他们没有写清楚。 文件非常混乱,甚至不好理解。 但是,我试图发布一个JSON数据是string化的: {"version":"1.0.1","sensors":[{"sensor":"accel","output":[{"name":"accelert","type":"dcmotion"}]}]} 我已经写在函数节点的API(这里的API是任意的,不是原创的) var msg = {"version":"1.0.1","sensors":[{"sensor":"accel","output":[{"name":"accelert","type":"dcmotion"}]}]} msg.headers: { 'x-api-key': 'ucasdfeacceacxfAIH2L4=', 'content-type': 'application/json" } 我从这里得到了这个例子: https : //groups.google.com/forum/#!msg/node-red/nl9Be0dN55g/S_VYMTjOanEJ 我添加input节点为HTTP POST,然后给予url并将其与添加了一个debugging节点的函数连接起来。 现在我部署了它。 我收到错误:API节点中意外的令牌 现在我不知道该怎么做。 我没有得到如何做到这一点。 请帮我一下 节点红色网站没有教程可用。

节点的JSvariables作用域与响应和http方法

我仍然试图解决这个问题,但这对我来说很困惑。 所以我使用http.get和一个pipe道与bl模块,我想它改变的内容,所以我可以使用它的function不工作,为什么? 我以为var会在我的文件中是全局的,这将允许我改变它。 var http = require('http'); var bl = require('bl'); var url1 = process.argv[2]; var content; http.get(url1, function(response){ response.pipe(bl(function(err,data){ return data.toString(); })); }); console.log(content.length); console.log(content);

log4js httpslogging端点

在log4js中,是否有任何选项可以使用HTTP端点来logging信息。 就像在温斯顿那样,你有通过指定host:port来logging到远程HTTP端点的HTTP传输,在log4js中有没有类似的东西?