provide怎么读 extended option怎么解决

使用nodejs+mongodb搭建简单个人博客时遇到的问题 - CNode技术社区
越努力,越幸运!!
1、package.json文件:
“name”: “blog”,
“version”: “0.0.0”,
“private”: true,
“scripts”: {
“start”: “node ./bin/www”
“dependencies”: {
“body-parser”: “~1.12.4”,
“cookie-parser”: “~1.3.5”,
“debug”: “~2.2.0”,
“ejs”: “~2.3.1”,
“express”: “~4.12.4”,
“morgan”: “~1.5.3”,
“serve-favicon”: “~2.2.1”,
“mongodb”: “*”,
“express-session”: “1.9.1”,
“connect-mongo”: “0.4.1”,
“connect-flash”: “0.1.1”
2、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 settings = require(’./settings’);
//引入flash(connect-flash)模块,flash是一个可以存储特定信息,显示完成后会被清除的模块
var flash = require(‘connect-flash’);
//这两个模块可以将 cookie 信息保存到 mongodb 中。
var session = require(‘express-session’);
var MongoStore = require(‘connect-mongo’)(session);
var app = express();
// view engine setup
app.set(‘port’, process.env.PORT || 3000);
app.set(‘views’, path.join(__dirname, ‘views’));
app.set(‘view engine’, ‘ejs’);
// uncomment after placing your favicon in /public
(favicon(__dirname + ‘/public/favicon.ico’));
app.use(logger(‘dev’));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(session({
secret: settings.cookieSecret,
key: settings.db,// cookie name
cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days
store: new MongoStore({
db: settings.db,
host: settings.host,
port: settings.port
//设置flash
app.use(flash());
app.use(express.static(path.join(__dirname, ‘public’)));
routes(app);
app.listen(app.get(‘port’),function(){
console.log('Express server listening on port ’ + app.get(‘port’));
3、工程的结构如下:
4、最后运行的时候,报了下面这个东西:
然后想请教一下大神们,这个问题该怎么去解决?困扰我一上午了。。。
看上去程序应该能运行吧,只是bson的路径有问题。怎么会到…/build/Release/bson呢?你检查一下mongodb:npm ls mongodb,看看有没有什么问题
嗯,,mongodb貌似没什么问题:
然后,之前的那个express-session启动警告deprecated undefined resave option的问题已经解决了
跪了、、、、
但是,现在又出现了一个新的问题,貌似是那个session的问题
额,数据库连上了么?
Google了一下,好像是要MongoStore连上之后再设置express的中间件,楼主可以看下这个讨论:
核心代码是:
var sessionStore = new MongoStore({ url: 'someConnectionUrl', db: 'audio-drop' }, function(e) {
var cookieParser = express.cookieParser('waytoblue');
app.use(cookieParser);
app.use(express.session({
store: sessionStore
app.listen();
嗯嗯,数据库是正常连接的。。。
嗯嗯,好的,多谢!!!
你这是2个版本的 mongodb 吗?
使用express4.x版和Jade模板重写《nodejs开发指南》微博实例
这个版本我跑了下,和你一样的错误。
你说的是这个吗。。。额 我也不清楚呢!怎么会有两个啊。。。
哥们,问题现在解决了吗?
我问的是你的nodejs连数据库是否正常
如何判断mongodb的连接
正常?mongodb 单独安装和 npm install mongodb 什么区别?
app.use(session({//session持久化配置
secret: &kvkenssecret&,
key: &kvkenskey&,
cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//超时时间
resave: false,
saveUninitialized: true,
store: new MongoStore({
db: &my_database&,
host: &localhost&,
port: 27017
你先把session代码注释了,然后尝试打开一次数据库看看
var MongoClient = require(‘mongodb’).MongoClient
, assert = require(‘assert’);
var url = ‘’;//数据库地址
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
console.log(“Connected correctly to server”);
db.close();
我写了存为mongo.js 运行起来 报错
你把项目传到git上一份,大家可以直接调试问题
对啊,你还是把项目上传一下吧,你肯定没有安装mongodb的模块啊。。
我怀疑是 数据库版本问题
这个博客例子 在express 与 mongodb 版本迭代的过程中出来了很多问题。express mongodb 都是最新版本的情况下,这个例子肯定跑步起来。虽然这个例子在以前是个很不错的入门练习。但是,我最近在ubuntu下配置最新版本的 express mongodb环境里,许多东西都变了,包括mongodb的连接方式。具体参看官网及资料。
个人建议:先配置好最新版本的node npm express mongodb 等环境下写个简单的数据库连接测试和数据读取,然后再参看这个例子的结构。
好了 最新的mongo连接方式变了,版本升到了3.0.3
有一步是下载安装mongodb, 然后在mongodb文件夹里再新建一个blog文件夹,
然后cd 到你的mongoInstallFolder
运行 mongod --dbpath blog/
这样启动了mongo之后,数据库成功了会说 “waiting for connections on port 27017” 一类的。
我之前遇到有关session和ttl多半是因为connect-mongo不兼容。我升级到了0.7.0就没出错了。
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
服务器赞助商为
,存储赞助商为
,由提供应用性能服务。
新手搭建 Node.js 服务器,推荐使用无需备案的自己做完实验并对比了网上的源码,有几地方需要注意。1.网上源码中有关body-parser()的问题。& & 这个问题,我在以前的讨论中已经做了比较明确的说明,现在重新说一下,就是新版本的Git中已经不再使用app.use(express.bodyParser())这种方法引入解析器,同样网上源码中给出的app.use(bodyParser())这种方式也有问题,在服务启动时会被自动忽略掉,所以要使用app.use(bodyParser.urlencoded({ extended: true }))这种方式进行引用。另外由于extended的默认值为true,如果使用app.use(bodyParser.urlencoded())的方式引用在服务启动时会提示“body-parser deprecated undefined extended: provide extended option”,虽然不影响使用,但是感觉不爽。2.网上源码中没有提及moment的引用。& & 自己在做实验时发现在加入时间以后list页总是报错,TypeError: views\pages\list.jade:24& & 22| & &td #{item.Country}& & 23| & &td #{item.Year}& & 24| & &td #{moment(item.meta.UpdateAt).format('MM/DD/YYYY')}开始觉得应该是moment模块的问题,不过在源码中没有找到,于是又反反复复看了几遍教学视频才在老师实验的那个时候找到了问题,就是moment模块没有被引用进去。所以同学们要小心,所有实用到的模块都要被引用啊!!!引用方法:app.local.moment = require('moment'),把这句话加在app.listen(PORT)之前就可以了。3.不知道浏览器有什么问题。& & 之前一直再使用360浏览器做测试,但是发现几个小问题:& & 1)在后台录入页上lable和text不在同一行上,列表页没有缩进(很难看);& & 2)在后台录入页提交以后redirect方法重定向到detail页上页面布局不对,反复刷新后可以正常。& & 开始以为是自己的代码有问题,反复对照多次后确认没有问题,最后想到了浏览器,更换IE浏览器实验以后发现一切正常,害死人啊!!!!(这个问题我只试了这两个浏览器,其它浏览器是不是有同样问题没有验证)& &&希望老师和同学们能帮忙解释一下上面的问题,谢谢
写下你的评论...
我也遇到同样的问题,有解决么?
var Movie = require('./models/movie')------&var Movie = require('../models/movie')
我也是卡在这里了,你们的解决了么?
点击展开后面18条评论
写下你的评论...
其实不该加的,你做了混淆和压缩就明白了
不加分号是对的?
不加分号,你给我压缩代码看看!
点击展开后面1条评论
写下你的评论...
写下你的评论...
发现是自己把 -col-md-2 写成了3...
写下你的评论...
也遇到过,已解决
在提交新电影时,显示 movie 未定义这个问题你是怎么解决的?
你的答案可能是我的这个答案 /qadetail/138602
写下你的评论...
写下你的评论...
找到问题了。。。。body-parser根本就没装
写下你的评论...
写下你的评论...
/rushui2018/note/372424 欢迎参考以下代码
写下你的评论...
Copyright (C)
All Rights Reserved | 京ICP备 号-2nodejs 使用app.use(express.bodyParser()); 出错 - 奉献获取 - ITeye博客
博客分类:
Error: Most middleware (like bodyParser) is no longer bundled with Express and m
ust be installed separately. Please see /senchalabs/connect#mi
at Function.Object.defineProperty.get (C:\Users\Administrator\AppData\Roamin
g\npm\node_modules\express\lib\express.js:89:13)
at Object.&anonymous& (C:\Users\Administrator\Desktop\nodejs\http\express1.j
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
根据错误可以知道bodyparser已经不和Express绑定在一起了,而需要单独来安装,执行如下命令即可:
npm install body-parser
然后在代码中如下使用:
var bodyParser = require('body-parser');
app.use(bodyParser());
不过还是无法工作,提示如下:
body-parser deprecated bodyParser: use individual json/urlencoded middlewares ex
press1.js:4:9
body-parser deprecated undefined extended: provide extended option node_modules\
body-parser\index.js:75:29
express deprecated res.send(status): Use res.status(status).end() instead expres
然后,可以发现已经过期了,可以使用如下代码代替:
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
我最终的一个实现如下:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.all('/', function(req, res) {
res.send(req.body.title + req.body.text);
app.listen(3000);
私人广告模块。。。下面依然是我建的一个公众帐号,可以关注一下哦,谢谢
浏览 13531
浏览: 767927 次
来自: 河北邯郸
u 写道老乡 ,邱县d老相好
老乡 ,邱县d
* 第一个参数为执行sqlOALib Journal期刊
费用:99美元
查看量下载量
A Bond Option Pricing Formula in the Extended CIR Model, with an Application to Stochastic Volatility
We provide a complete representation of the interest rate in the extended CIR model. Since it was proved in Maghsoodi (1996) that the representation of the CIR process as a sum of squares of independent Ornstein-Uhlenbeck processes is possible only when the dimension of the interest rate process is integer, we use a slightly different representation, valid when the dimension is not integer. Our representation consists in an infinite sum of squares of basic processes. Each basic process can be described as an Ornstein-Uhlenbeck process with jumps at fixed times. In this case, the price of a bond option resembles the Black-Scholes formula, where the normal distribution is replaced by the generalized chi-square distribution. The formula is in closed form, up to the solution of a Riccati equation for the bond price of the option. We then provide a generalization of our representation to an extended CIR model with stochastic volatility. We present a closed form approximation of the price of a bond option, valid when the expiration of the option is small and the speed of mean-reversion of volatility is high. The approximation is in "full" closed form, i.e., it does not require to solve an ordinary differential equation.
Please enable JavaScript to view the
&&&OALib Suggest
Live SupportAsk us anything

我要回帖

更多关于 provide sth for sb 的文章

 

随机推荐