使用最新的mongoose更新,您不再能够像我一样使用模型.我需要在整个应用程序中共享相同的数据库连接.
https://github.com/LearnBoost/mongoose/issues/1249
这是旧的方式,不再有效:
./models/user.js
var mongoose = require('mongoose'), cfg = require('../config')
, Schema = mongoose.Schema
, db = mongoose.createConnection(cfg.mongo.uri, cfg.mongo.db);
...
module.exports = db.model('Item', ItemSchema);
Run Code Online (Sandbox Code Playgroud)
如何在上面的github问题中建议重新使用数据库连接?
我var User = require('./models/user');在我的代码库中的几个不同的地方使用.
我想在UI更新时钟时,从时间的变化12:01来12:02.
我可以每隔60秒做一次setInterval,但是开始可能不会在新的一分钟的第一秒.我怎样才能确保它在第一秒开始?
我想我需要找出当前分钟剩余的秒数,然后执行一个setTimeout,在秒过去时触发setInterval.
var secondsLeft = ?; //calculate seconds left in this minute
setTimeout(function(){
setInterval(function(){
//update clock
}, 1000 * 60);
}, secondsLeft);
Run Code Online (Sandbox Code Playgroud)
如果moment.js让它变得更容易,那对我来说没问题.
我必须创建一个视频播放器对象,但是在创建视频播放器之前,我需要流对象存在。
该this.stream由vuex数据存储填充。但我发现mounted()and created()方法不会等待存储数据出现。
这是Player.vue组件:
import Clappr from 'clappr';
import { mapActions, mapGetters } from 'vuex';
import * as types from '../store/types';
export default {
name: 'streams',
data() {
return {
player: null
};
},
computed: {
...mapGetters({
stream: types.STREAMS_RESULTS_STREAM
}),
stream() {
return this.$store.stream;
}
},
methods: {
...mapActions({
getStream: types.STREAMS_GET_STREAM
})
},
mounted() {
this.getStream.call(this, {
category: this.$route.params.category,
slug: this.$route.params.slug
})
.then(() => {
this.player = new Clappr.Player({
source: this.stream.url, …Run Code Online (Sandbox Code Playgroud) 我正在使用node.bcrypt.js哈希返回node.js中的十六进制数字作为密码重置令牌.
user.reset_password_token = require('crypto').randomBytes(32).toString('hex'
);
Run Code Online (Sandbox Code Playgroud)
在我在网址中传递令牌之前,我是否还应该对该令牌进行base64编码(即:链接重置电子邮件)?
这样做有什么好处吗?
我似乎记得base64编码可以包含正斜杠,这会弄乱路径:
var token = user.reset_password_token;
//is there any benefit to doing base64 encoding?
var encoded_token = new Buffer(token).toString('base64');
var reset_link = 'http://example.com/reset/'+ encoded_token;
sendResetLink( reset_link );
Run Code Online (Sandbox Code Playgroud) 如何使用jQuery遍历祖先?
当前代码陷入递归循环:
HTML:
<html>
<body>
<div>
<ul>
<li></li>
</ul>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JS:
function traverse($node){
while ( $node.get(0) !== $("html").get(0) ) {
console.log($node);
traverse($node.parent());
}
}
//traverse($("ul li"));
Run Code Online (Sandbox Code Playgroud)
要观察问题,请取消注释最后一行,但要注意它可能会冻结您的浏览器.
在JSFiddle上也一样:http://jsfiddle.net/WpvJN/1/
防止双击jQuery链接的最佳方法是什么?
我有一个触发ajax调用的链接,当ajax调用返回时它会显示一条消息.
问题是如果我双击,或者在ajax调用返回之前单击它两次,当我真的只想要一个时,我最终会在页面上显示两条消息.
我需要像disabled按钮上的属性.但这不适用于链接.
$('a').on('click', function(e){
e.preventDefault();
//do ajax call
});
Run Code Online (Sandbox Code Playgroud) 我不太清楚的语法,但我正在用逗号分隔的属性列表$properties,并希望用逗号加入他们的行列,所以(background-color, color)成为background-color .5s, color .5s
@mixin transition($properties, $duration) {
$props: ();
@each $prop in $properties {
$tmp: $prop unquote($duration);
$props: append($props, $tmp);
}
$str: join($props, ',');
-moz-transition: $str, -moz-transform $duration;
-webkit-transition: $str, -webkit-transform $duration;
-o-transition: $str, -o-transform $duration;
transition: $str, transform $duration;
}
Run Code Online (Sandbox Code Playgroud)
我实际上得到的是:
border-color 0.5s background-color 0.5s ",", -moz-transform 0.5s
Run Code Online (Sandbox Code Playgroud)
什么时候应该是:
border-color 0.5s, background-color 0.5s, -moz-transform 0.5s
Run Code Online (Sandbox Code Playgroud) 我@reboot ~/www/example.com/bin/server在我的用户的crontab中使用...但是当我重新启动服务器时,Web服务器(此脚本)没有出现.(脚本在命令行中工作正常).
我的猜测是/home/user目录尚未安装...有没有人知道是否可以使用此crontab @reboot方法让脚本在主目录中运行?
我想在 Express 中使用 robots.txt 文件中的一些变量。
如何将此文件呈现为 EJS 模板?我已经让 EJS 可以处理 .html 文件。
app.route('/robots.txt')
.get(index.robotstxt);
/**
* Send robotstxt file
*/
exports.robotstxt = function (req, res) {
res.type('text/plain');
res.render('robots.txt', {
home: config.home
});
};
# robotstxt.org
User-agent: *
Disallow: /settings
Disallow: /account/
Allow: /
sitemap: <%= home %>/sitemap.xml
Run Code Online (Sandbox Code Playgroud)
目前,我刚刚收到以下错误:
Error: Cannot find module 'txt' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at new View (/Users/user/projects/app/node_modules/express/lib/view.js:43:49) at Function.app.render (/Users/user/projects/app/node_modules/express/lib/application.js:484:12) at ServerResponse.res.render (/Users/user/projects/app/node_modules/express/lib/response.js:777:7) at Object.exports.robotstxt [as handle] (/Users/user/projects/app/lib/controllers/index.js:29:6) …Run Code Online (Sandbox Code Playgroud) import cfg from 'dotenv-flow';\n\ncfg.config();\n\nconst {\n HOST_USER,\n HOST_DOMAIN,\n HOST_PATH,\n HOST_PROJECT,\n PORT,\n VITE_API_ENDPOINT,\n APP_URL,\n NODE_ENV\n} = process.env;\n\nconst env_production = {\n HOST_USER,\n HOST_DOMAIN,\n HOST_PATH,\n HOST_PROJECT,\n PORT,\n VITE_API_ENDPOINT,\n APP_URL,\n NODE_ENV\n};\n\nconsole.log(env_production);\nmodule.exports = {\n apps: [\n {\n name: 'grazily-ui',\n script: './build/index.js',\n env_production\n }\n ]\n};\nRun Code Online (Sandbox Code Playgroud)\n出现此错误:
\n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82 id \xe2\x94\x82 name \xe2\x94\x82 mode \xe2\x94\x82 \xe2\x86\xba \xe2\x94\x82 status \xe2\x94\x82 cpu \xe2\x94\x82 memory \xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xa4\n\xe2\x94\x82 0 \xe2\x94\x82 index \xe2\x94\x82 fork \xe2\x94\x82 0 \xe2\x94\x82 stopped \xe2\x94\x82 0% \xe2\x94\x82 0b \xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\n[PM2][ERROR] File ecosystem.config.js malformated\nError [ERR_REQUIRE_ESM]: require() of ES Module /home/ettinger/www/grazily.com/grazily-ui/ecosystem.config.js from …Run Code Online (Sandbox Code Playgroud)