节点JS浏览器模拟(cookies,会话,标题)

我需要像一个普通的浏览器从节点js请求。 我是什么意思? 我可以设置任何HTTP信息,如Cookie,标题,正文。 所以要build立HTTP请求,我想要的。 请求发出后,所有的响应数据应该是可读的,比如Set Cookie …. 如果可以在会话期间自动保存cookie,那将会很棒。 所以我不需要在每次进一步提出请求时都包含它们。 所以只需模拟一个真实的浏览器来保持会话 有没有任何框架的库可以提供这样的function?

Angular 4+ Express不是从Heroku开始的

我试图将我的angular度4应用程序部署到heroku,但我得到的错误,如不能find“ng命令”等。 我gussing我需要改变package.json中的东西强制它安装CLI,但我不能得到它的工作。 这里是package.json: { "name": "q", "version": "0.0.0", "license": "MIT", "watch": { "run-watch": { "patterns": [ "src", "server", "e2e" ], "extensions": "js,ts,css,scss,html" } }, "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build && node server/server.js", "run-watch": "ng build && node server/server.js", "lint": "ng lint", "e2e": "ng e2e", "watch": "npm-watch" }, "private": true, "dependencies": […]

Mongoose / Express / Nodejs尝试从服务器传递一个variables到html

我试图从我的server.js文件传递一个variables到HTML,但variables不会显示在我的EJS文件。 我一定会错过一些东西,因为它正在另一个路线(与另一个EJS文件),但我看不到我想要通过的forms或variables。 如果我把表单之外的任何东西都显示出来,但表单本身不会显示出来,我可以从我的服务器console.log,它显示我从我的模型findvariables,它通过callback错误testing。 我已经尝试使用工作EJS代码的forms,并不会显示。 再次,它是去正确的地方,因为我可以把任何东西以外的forms。 此外,我没有得到一个错误,表单或variables只是不显示在EJS文件中。 如果我更改了我的<%%>标签内的任何内容(如下所示): <% for(var i=0;i<turtles.length;i++){ %> 它导致一个错误说(例如)乌龟(/例)没有定义。 所以它知道它在那里。 先谢谢你。 我的server.js文件: edit: function(req, res){ Turtle.findOne({_id: req.params.id}, function(err, turtle){ if(err){} else{ console.log(turtle._id); res.render("edit", {turtles:turtle})} }) }, 我的edit.ejs: <% for(var i=0;i<turtles.length;i++){ %> <h3><%= turtles[i].name %></h3> <form action='/turtles/<%= turtles[i]._id %>' method='post'> <p>Name: <input type='text' name='name' value="<%= turtles[i].name %>"></p> <p>Favorite color: <input type='text' name='favecolor' value="<%= […]

单独的Web和工作进程,是否应为每个进程build立一个新的连接?

我目前正在尝试构build一个具有Web和工作进程的NodeJS Web应用程序,并使用AMQP在它们之间进行通信。 使用我当前的设置,启动应用程序包括启动Web进程的脚本( server.js )和工作进程的另一个脚本( worker.js )。 每个文件都include第三个文件, amqp.js ,它使用一个启动函数,包括创build一个连接,然后创build一个通道,然后声明队列。 然而,在试图debugging另外一个问题时,我碰到了这篇文章 ,它显示了一个不同的结构:首先创build一个连接,然后启动两个进程,每个进程创build一个通往该连接的通道并断言两个队列。 我应该为每个工作人员build立一个新的连接吗?我可以在networking和工作人员分开的环境中实现这个连接吗?

合并名称空间和variables的声明

我正在尝试为第三方库node-tap创build声明文件。 简化的问题是:对于图书馆 // node_modules/a/index.js function A() { /* … */ } module.exports = new A(); module.exports.A = A; 什么是一个正确的*.d.ts声明文件,以允许下面的代码编译成功? // test.ts import * as a from 'a'; import {A} from 'a'; function f(): A { return a; } 提到将A作为types是重要的,尽pipe在这个简单的例子中可以省略它。

Firebase FCM错误:“InvalidRegistration”

目前,我正尝试使用FCM在Firebase Cloud Functions的帮助下向Device Group发送PushNotification ,但一旦发送通知,它将返回代码200但会失败: SUCCESS response= { multicast_id: 8834986220110966000, success: 0, failure: 1, canonical_ids: 0, results: [ { error: 'InvalidRegistration' } ] } 这里是我用来发送这个通知的代码…我错过了什么? const options = { method: 'POST', uri: 'https://fcm.googleapis.com/fcm/send', headers: { 'Authorization': 'key=' + serverKey, }, body: { to: groupId, data: { subject: message }, notification: { title: title, body: body, […]

如何在我的情况下连接到elasticache?

我试图从我的应用程序连接到aws elasticache。 我知道端点和端口,但由于某种原因,我无法连接到它。 我使用了这个npm包: https ://www.npmjs.com/package/node-memcached-client 码: const Memcached = require('node-memcached-client'); const client = new Memcached({ host: 'mycache.aa11c.0001.use2.cache.amazonaws.com', //fake aws cache endpoint port: 11211 }); console.log(client); // I can see it outputs stuff client.connect() .then(c => { console.log('connected'); console.log(c); }).catch(function(err){ console.log('error connecting'); console.log(err); }); 出于某种原因,当我运行代码时,我所看到的就是 [Memcached] INFO: Nothing any connection to mycache.aa11c.0001.use2.cache.amazonaws.com:11211, created sid:1 console.log没有错误或connected消息。 […]

我应该如何在Javascript中使用node.js和Mongodb实现asynchronousfunction?

到目前为止,我已经看到,有setTimeout() , process.nextTick(function)的asynchronousfunction,但我不知道如何使用它。 我试过我的代码,因为我现在需要一个asynchronousfunction,但它将Can't set headers after they are sent. 这是我的代码: var MongoClient = require('mongodb').MongoClient; var url = 'mongodb://localhost:27017/myproject'; var updateRecord = function(db, req, callback) { db.collection('documents').updateMany({ 'Item Description': req.body.itemDescrip }, { $set: { 'Issued QTY': req.body.issueQty } }, function(err, results) { if (err) return callback(err); console.log('Done'); console.log(results); var cursor = db.collection('documents').find({ 'Item Description': req.body.itemDescrip, […]

在create-react-app项目中增加JavaScript堆大小

节点通过传入–max-old-space-size命令行标志来增加堆大小。 在create-react-app项目中,一切都取决于使用react-scripts。 如何在这样的项目中传递这个参数,我应该在哪里做最好的? 谢谢你的帮助。

无法升级到Angular4

是的,我知道已经有成千上万个类似的问题了 – 不,没有一个答案对我有用。 我刚刚在升级Angular时遇到了一些问题,只是决定忽略新的更新。 起初,我使用了“标准”升级命令: npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest –save然而,导致出现以下错误(+最后有很多警告): +– @angular/animations@4.1.3 +– @angular/common@4.1.3 +– UNMET PEER DEPENDENCY @angular/compiler@4.1.3 +– @angular/compiler-cli@4.1.3 invalid | +– @angular/tsc-wrapped@4.1.3 | | `– tsickle@0.21.6 | `– reflect-metadata@0.1.10 +– UNMET PEER DEPENDENCY @angular/core@4.1.3 +– @angular/forms@4.1.3 +– @angular/http@4.1.3 +– @angular/platform-browser@4.1.3 +– @angular/platform-browser-dynamic@4.1.3 […]