我正在做一个包含子项目的Node.js项目.一个子项目将有一个Mongodb数据库,Mongoose将用于包装和查询db.但问题是
要使用多个mongoose实例,Node.js不允许多个模块实例,因为它具有缓存系统require()
.我知道在Node.js中禁用模块缓存,但我认为这不是一个好的解决方案,因为它只需要mongoose.
我曾尝试使用createConnection()
和openSet()
猫鼬,但它不是解决方案.
我试图深度复制mongoose实例(http://blog.imaginea.com/deep-copy-in-javascript/)以将新的mongoose实例传递给子项目,但它会抛出RangeError: Maximum call stack size exceeded
.
我想知道是否有使用多个数据库与mongoose或任何解决方法来解决这个问题?因为我认为猫鼬非常容易和快速.或任何其他模块作为建议?
我正在尝试安装node-g.raphael
,我收到以下错误:
Bender-03:htdocs alfred$ sudo npm install node-g.raphael --save
Password:
> contextify@0.1.15 install
/Users/alfred/Sites/twistedgeo/htdocs/node_modules/contextify
> node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir
'/Users/alfred/Sites/twistedgeo/htdocs/node_modules/contextify/build'
gyp ERR! System Darwin 16.7.0
gyp ERR! command "/usr/local/bin/node"
"/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js"
"rebuild"
gyp ERR! cwd
/Users/alfred/Sites/twistedgeo/htdocs/node_modules/contextify
gyp ERR! node -v v8.8.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: contextify@0.1.15
(node_modules/contextify):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: contextify@0.1.15
install: `node-gyp rebuild`
npm WARN …
Run Code Online (Sandbox Code Playgroud) 当我运行npm start运行我的快速应用程序时,我收到此错误.
TypeError: Router.use() requires middleware function but got a Object
Run Code Online (Sandbox Code Playgroud)
我的app.js代码
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public'))); …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个新项目,其中react/express作为前端和环回作为后端api.我在开发环境中使用不同的端口将它们分开.
我该如何在生产中部署它们?
托管在同一台服务器上 - 将后端与不同的子域分开?
托管在2个不同的服务器上 - 似乎无法使用同一个域.
Python(scipy.stats.hmean
)中的Harmonic Mean函数要求输入为正数.
例如:
from scipy import stats
print stats.hmean([ -50.2 , 100.5 ])
Run Code Online (Sandbox Code Playgroud)
结果是:
ValueError: Harmonic mean only defined if all elements greater than zero
Run Code Online (Sandbox Code Playgroud)
我没有在数学上看到为什么会出现这种情况,除了罕见的情况,你最终将除以零.不是检查除以零,而是hmean()
在输入任何正数时抛出错误,无论是否可以找到调和平均值.
我在数学中遗漏了什么吗?或者这真的是一个限制SciPy
吗?
你如何找到一组数字的调和平均值,这些数字在python中可能是正数还是负数?
当我尝试从页面登录时,我收到了错误return done(null, false, req.flash('loginMessage', 'User does not exist'));
TypeError: req.flash is not a function
.
以下是我的server.js和passport.js配置:
server.js:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var session = require('express-session');
var ejs = require('ejs');
var mongoose = require('mongoose');
var passport = require('passport');
var flash = require('connect-flash');
mongoose.connect('mongodb://localhost:mydb');
require('./config/passport')(passport);
app.use(express.static('public'));
app.set('view engine', 'ejs');
app.set('views', __dirname+'/public/views');
app.use(bodyParser.urlencoded({'extended':'true'}));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(session({secret:'learningpassport',
resave: true,
saveUnitialized: true}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
require('./app/routes')(app,passport);
app.listen(3000);
Run Code Online (Sandbox Code Playgroud)
配置/ passport.js:
var LocalStrategy = …
Run Code Online (Sandbox Code Playgroud) 关于flash,connect-flash和express-flash之间究竟有什么区别我还是有点困惑.
安装:
闪npm install flash
快递:npm install express-flash
连接闪存:npm install connect-flash
用法:
闪光:
app.use(session()); // session middleware
app.use(require('flash')());
app.use(function (req, res) {
// flash a message
req.flash('info', 'hello!');
next();
})
Run Code Online (Sandbox Code Playgroud)
连接闪存
var flash = require('connect-flash');
var app = express();
app.configure(function() {
app.use(express.cookieParser('keyboard cat'));
app.use(express.session({ cookie: { maxAge: 60000 }}));
app.use(flash());
});
Run Code Online (Sandbox Code Playgroud)
express-flash它甚至要求使用的设置方式与connect-flash相同:
var flash = require('express-flash'),
express = require('express'),
app = express();
app.use(express.cookieParser('keyboard cat'));
app.use(express.session({ cookie: { maxAge: 60000 }}));
app.use(flash()); …
Run Code Online (Sandbox Code Playgroud) 如果我们这样做:
npm link x
Run Code Online (Sandbox Code Playgroud)
然后我们运行npm install
,它将覆盖符号链接包。
有没有办法在npm install
不覆盖符号链接包的情况下运行?就像是:
npm install --preserve-symlinks
Run Code Online (Sandbox Code Playgroud)
或者
npm install --keep-symlinks
Run Code Online (Sandbox Code Playgroud)
这是 NPM 问题跟踪器中的问题:https :
//github.com/npm/npm/issues/17287
所以,我一直在试图安装使用现在的电报机器人,但我得到了ELIFECYCLE打字时的错误npm start
。我有最新版本的 nodejs 和 npm。
该脚本确实有效,因为当我运行时node index.js
效果很好,只有当我尝试npm start
或尝试立即部署它时才会出现问题。
我在最新的 Fedora 上运行这个
所以这是我尝试运行时的错误 npm start
[root@localhost my-telegram-bot]# npm start
> telegram-bot@1.0.0 start /home/fedora/Scrivania/my-telegram-bot
> node index.js
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::430
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at Server._listen2 (net.js:1258:14)
at listen (net.js:1294:10)
at Server.listen (net.js:1390:5)
at EventEmitter.listen (/home/fedora/Scrivania/my-telegram-
bot/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/fedora/Scrivania/my-telegram-bot/index.js:43:5)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
npm ERR! Linux 4.13.5-200.fc26.x86_64 …
Run Code Online (Sandbox Code Playgroud) 我最近开始使用c ++,我选择学习c ++ 11的功能.但是c ++代码的运行方式有时并不那么明显.
下面是我的代码.在那部分,decltype(std::move(sample)) sample2 = std::move(sample);
我不知道为什么这一行不会调用移动构造函数.你能解释一下原因吗?
#include <iostream>
class AAA
{
public:
AAA() { std::cout << "default constructor" << std::endl; }
AAA(const AAA& cs) { std::cout << "copy constructor" << std::endl; }
AAA(AAA&& cs) { std::cout << "move constructor" << std::endl; }
~AAA() { std::cout << "destructor" << std::endl; }
};
int main(int argc, char* args[])
{
AAA sample;
// ((right here))
decltype(std::move(sample)) sample2 = std::move(sample);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它是在[ubuntu 16.04 …
node.js ×7
npm ×3
express ×2
javascript ×2
backend ×1
c++ ×1
c++11 ×1
database ×1
decltype ×1
deployment ×1
frontend ×1
macos ×1
math ×1
mean ×1
mongodb ×1
mongoose ×1
npm-install ×1
passport.js ×1
python ×1
reactjs ×1
scipy ×1
statistics ×1
stdmove ×1
symlink ×1
telegram ×1