在通过护照实例的快速路由中路由分离

我正在尝试将用户login模块添加到节点中的现有应用程序。 它使用单独的路由文件为每个模块和一个主路由文件使用最终在server.js中使用的所有子路由当我尝试将passport实例传递给用户路由时,由于未定义passport,因此导致错误。 这里是我的应用程序代码和结构: app views user index.ejs login.ejs signup.ejs profile.ejs routes docs index.js user index.js index.js config passport.js server.js server.js const express = require('express') const app = express() const path = require('path') const bodyParser = require('body-parser') const cookieParser = require('cookie-parser') const passport = require('passport') const flash = require('connect-flash') const session = require('express-session') const routes = […]

为什么我不能访问mongoose模式的方法?

我有一个Nodejs应用程序中的这个Mongoose模式: const mongoose = require('mongoose'), Schema = mongoose.Schema, sodium = require('sodium').api; const UserSchema = new Schema({ username: { type: String, required: true, index: { unique: true } }, salt: { type: String, required: false }, password: { type: String, required: true } }); UserSchema.methods.comparePassword = function(candidatePassword, targetUser) { let saltedCandidate = candidatePassword + targetUser.salt; if […]

Woocommerce api列出了所有现在全部返回的产品

我正在使用节点(js)的woocommerce-api,由于某种原因,无论我尝试这个代码块只保留返回10个产品,而不是整个列表。 有人有build议吗。 提前致谢。 WooCommerce.get('products', function(err, data, res) { if (res !== null) { allItems = JSON.parse(res); } });

将angularjs应用程序从Windows移动到Ubuntu

我使用nodejs,http-server,gulp和brackets在窗口上开发了一个angular度应用程序。 在Windows中我有一个根目录(lms)包含: /src /src/templates /src/js /src/img /src/index.html /node_modules package.json 在Ubuntu中,我有一个名为/ home / lms的目录。 我已经安装了nodejs,angularjs和http服务器,但不是吞咽或凉亭,因为我不会在Ubuntu中进行开发。 我在家看到/ lms: /Public /Templates /Pictures /node_modules 我如何部署我的文件? 我假设我把我的package.json放在home / lms中,但是我不能将Windows node_modules复制到Ubuntu node_modules,所以如何为Ubuntu创buildnode_modules? 另外,我把我的应用程序目录/ src放到Ubuntu的/ home / lms / Public目录下,或者只是把它添加到/ home / lms?

在回送中的REST连接器查询中复制密钥

我想问你是否知道我怎么可能在环回REST连接器查询中重复参数。 我有以下代码: details: { 'template': { 'method': 'GET', 'debug': true, 'url': 'https://www.example.com/data', 'timeout': 10000, 'headers': { 'Authorization': 'Bearer {token}' }, 'query': { q: 'PHOTOS' q: 'DETAILS', id: '{id}' }, 'options': { 'useQuerystring': true }, 'responsePath': '$' }, 'functions': { 'searchData': [ 'token', 'id' ] } } 问题在于,看起来loopback覆盖了最后一个参数q的值,因为我只获取最后一个参数的信息。 任何想法如何解决它? 谢谢你,

为什么mongo不能返回所有的字段?

我有一个位置和名称作为字段的集合。 我用下面的mongoose创build了名字索引, eventSchema.index({name: 'text'}); 当我运行这个robomongo,它返回所有12个字段, db.getCollection('_event').find({"location.country":"United States"}) 但是当我运行这个robomongo,它只返回值与两个字段,ID和位置, db.getCollection('_event').find({$text: {$search: "2017 Honda"}},{"location.country":"United States"})

Webpack – 获取节点模块进入Bundle并加载到html文件

我正试图通过WebPack在浏览器中使用node_modules。 我读过教程和开始的步骤,但卡住了。 我已经使用webpack生成下面的webpackconfigurationbundle.js和去浏览我的index.html在Chrome浏览器中我得到的错误: Uncaught ReferenceError: require is not defined at Object.<anonymous> (bundle.js:205) 我需要做什么额外的步骤才能让浏览器识别要求? 的index.html <script src="bundle.js"></script> <button onclick="EntryPoint.check()">Check</button> index.js const SpellChecker = require('spellchecker'); module.exports = { check: function() { alert(SpellChecker.isMisspelled('keng')); } }; 的package.json { "name": "browser-spelling", "version": "1.0.0", "description": "", "main": "index.js", "dependencies": { "node-loader": "^0.6.0", "spellchecker": "^3.3.1", "webpack": "^2.2.1" } } webpack.config.js module.exports = […]

Node.JS Express的承诺问题

我正在研究Node.JS / Express应用程序。 我正在使用Jade作为模板引擎。 我正在经历一些奇怪的行为。 我有一个模拟API,返回一个简单的数组到我的Jade模板。 我已经从服务器的angular度validation了API的作品。 但是,每当我第一次启动服务器时,我都会去那个特定的页面,我收到一个错误 TypeError: Cannot read property 'length' of undefined at routes.js:28:34 at Layer.handle [as handle_request] (E:\dev\code\javascript\ps_resume_express\node_modules\express\lib\router\layer.js:95:5) at next (E:\dev\code\javascript\ps_resume_express\node_modules\express\lib\router\route.js:131:13) at Route.dispatch (E:\dev\code\javascript\ps_resume_express\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (E:\dev\code\javascript\ps_resume_express\node_modules\express\lib\router\layer.js:95:5) at E:\dev\code\javascript\ps_resume_express\node_modules\express\lib\router\index.js:277:22 at Function.process_params (E:\dev\code\javascript\ps_resume_express\node_modules\express\lib\router\index.js:330:12) at next (E:\dev\code\javascript\ps_resume_express\node_modules\express\lib\router\index.js:271:10) at Function.handle (E:\dev\code\javascript\ps_resume_express\node_modules\express\lib\router\index.js:176:3) at router (E:\dev\code\javascript\ps_resume_express\node_modules\express\lib\router\index.js:46:12) 每当我开始启动服务器时,都会发生这种情况。 但是,只要它保持运行,后续的调用就可以工作,并且页面被正确渲染。 这是我的路线方法 router.get('/skills', (req, res) => { […]

什么是节点subprocess?

我正在阅读包含child_process库的node.js项目。 究竟是一个孩子的过程? 这是类似的JavaScriptnetworking工作者? 在subprocess中运行进程有什么优势,而不是简单地执行它? 我假设这一些如何让你更多的访问内存?

CloudFlare“SSL:灵活的”HTTPS不能在自定义端口上工作

我在CloudFlare上的域名指向了DigitalOcean Droplet的IP地址。 当尝试使用自定义端口通过CloudFlare上的域访问网站时,我得到: error 525 SSL handshake failed 。 我的CloudFlare Crypto SSL is set to: Flexible (…据我所知 – 在DigitalOcean液滴上不需要SSL)。 示例地址: 通过DigitalOcean IPv4 (服务器上没有安装SSL) http://46.101.xxx.xxx/ – 100%的工作 https://46.101.xxx.xxx/ – 0%根本不工作(服务器设置为:80) http://46.101.xxx.xxx:2053/api – 100%的工作 http://46.101.xxx.xxx:2083/ – 100%的工作 通过CloudFlare : https://example.com/ – 100%的工作 https://example.com:2053/api – 来自CloudFlare的50%错误:525 SSL握手失败 https://example.com:2083/ – 来自CloudFlare的50%错误:525 SSL握手失败 我将服务器configuration为使用为https连接保留的端口:https: //support.cloudflare.com/hc/en-us/articles/200169156-Which-ports-will-Cloudflare-work-with- 当我设置主服务器使用端口:443而不是:80它显然不工作,因为我没有服务器上的SSL。 https://example.com:2053/api应该如何configuration为与CloudFlare配合使用?