我想用一些控制台扩展来创建一个简单的服务器http服务器.我找到了从命令行数据中读取的代码段.
var i = rl.createInterface(process.stdin, process.stdout, null);
i.question('Write your name: ', function(answer) {
console.log('Nice to meet you> ' + answer);
i.close();
process.stdin.destroy();
});
Run Code Online (Sandbox Code Playgroud)
好好反复问问题,我不能简单地使用while(done) { }
循环?如果服务器在提问时接收输出也很好,它会破坏该行.
我想让关键项目在该系列中独一无二,但我无法使其正常工作,我在这里发现了类似的问题.
task.js
function make(Schema, mongoose) {
var Tasks = new Schema({
project: { type: String, index: { unique: true, dropDups: true }},
description: String
});
mongoose.model('Task', Tasks);
}
module.exports.make = make;
Run Code Online (Sandbox Code Playgroud)
test.js
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/rss');
var Schema = mongoose.Schema
, ObjectId = Schema.ObjectId;
require('./task.js').make(Schema, mongoose);
var Task = mongoose.model('Task');
var newTask = new Task({
project: 'Starting new project'
, description: 'New project in node'
});
newTask.save(function(err) {
if (err) console.log('Error on saving');
});
mongoose.disconnect();
Run Code Online (Sandbox Code Playgroud)
当我使用节点test.js运行应用程序时,仍然会创建重复项.
MongoDB shell version: …
Run Code Online (Sandbox Code Playgroud) 有没有更好的方法来填充基于Jade的选择字段,我目前正在使用此示例.有没有更好的方法来破坏模板代码?
项目值是"天"示例.
select
repeation = [ 'no-repeat', 'day', 'week', 'month']
for item in repeation
if job.repeat == item
option(selected="true") #{item}
else
option #{item}
Run Code Online (Sandbox Code Playgroud)
当项目是['day','week']的数组时,还要显示多个选项呢?
//为多个元素编辑小的可能解决方案
enginges = [ 'google', 'bing', 'yahoo', 'duckduckgo']
for engine in enginges
option(selected=job.sources.indexOf(engine) != -1) #{engine}
Run Code Online (Sandbox Code Playgroud) 问题是我无法使用关系hasOne,它不会急于加载状态类型对象.
所有查询都在现有表上完成.
这是客户表,重要的是这个cst_state_type
领域:
module.exports = function(sequelize, DataTypes) {
return sequelize.define('customer', {
customer: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: true,
validate: {
isNumeric: true
}
},
first_name: {
type: DataTypes.STRING(100),
validate: {
isAlphanumeric: true
}
},
last_name: DataTypes.STRING(100),
identity_code: {
type: DataTypes.STRING(20),
allowNull: true,
validate: {
isNumeric: true
}
},
note: DataTypes.STRING(1000),
birth_date: DataTypes.DATE,
created_by: DataTypes.INTEGER,
updated_by: DataTypes.INTEGER,
cst_type: DataTypes.INTEGER,
cst_state_type: {
type: DataTypes.INTEGER,
}
}, {
tableName: 'customer',
updatedAt: 'updated',
createdAt: 'created',
timestamps: true
});
}; …
Run Code Online (Sandbox Code Playgroud) 我一直在寻找简单的数据库抽象实现,然后我找到了很棒的文章http://howtonode.org/express-mongodb,虽然很旧,但我仍然喜欢这个想法.
也许构造,可以采取某种对象文字与数据库设置.所以主要的想法是可能有不同的UserService-s实现,但位于不同的目录中,只需要一个需要的目录.
/data-layer/mongodb/user-service.js
/post-service.js
/comment-service.js
/data-layer/couchdb/user-service.js
/post-service.js
/comment-service.js
Run Code Online (Sandbox Code Playgroud)
当需要数据库时,我会在var UserService = require(__dirname + '/data-layer/mongodb/user-service).UserService(db);
哪里得到它var db = "open db object"
这是正确的做法吗?还是有更好的解决方案?
问题是当您触发 1k-2k 传出 HTTP 请求时实际发生了什么?我看到它可以通过 500 个连接轻松解决所有连接,但是从那里向上移动似乎会导致问题,因为连接保持打开状态并且 Node 应用程序将卡在那里。使用本地服务器 + 示例 Google 和其他模拟服务器进行测试。
因此,对于一些不同的服务器端点,我确实收到了原因:读取 ECONNRESET 很好,服务器无法处理请求并抛出错误。在 1k-2k 请求范围内,程序将挂起。当您检查打开的连接时,lsof -r 2 -i -a
您可以看到有一些 X 数量的连接一直挂在那里0t0 TCP 192.168.0.20:54831->lk-in-f100.1e100.net:https (ESTABLISHED)
。当您向请求添加超时设置时,这些可能最终会出现超时错误,但为什么否则连接会永远保持下去并且主程序最终会处于某种不确定状态?
示例代码:
import fetch from 'node-fetch';
(async () => {
const promises = Array(1000).fill(1).map(async (_value, index) => {
const url = 'https://google.com';
const response = await fetch(url, {
// timeout: 15e3,
// headers: { Connection: 'keep-alive' }
});
if (response.statusText !== 'OK') {
console.log('No ok received', index);
} …
Run Code Online (Sandbox Code Playgroud) 我已经搜索了这个主题很长一段时间,目前所有的解决方案和示例都在git中工作,但没有针对Mercurial的直接解决方案.
从类似链接的某个地方采取的工作示例.
"private": true
to your package.json
Then to reference private npm module in package.json
{
"name": "myapp",
"dependencies": {
"private-repo": "git+ssh://git@github.com:myaccount/myprivate.git#v1.0.0",
}
}
Run Code Online (Sandbox Code Playgroud)
当我从官方的npm页面阅读时,这一切都只适用于git https://npmjs.org/doc/json.html#Git-URLs-as-Dependencies
那么如何在Mercurial中做同样的事情,或者目前它似乎只能用Git进行?
问题是如何在特定选项卡上查询此类事件:
目前,我已经研究过检查指定URL操作的最简单方法是使用内容脚本,它可以侦听事件,然后将带有消息API的结果发送到后台脚本.
我得到了简单的代码,也许问题依赖于给定的格式字符串或时区.所以这是代码:
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
try {
Date added = df.parse("00:00");
System.out.println(added);
System.out.println(added.getTime());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
结果是:Thu Jan 01 00:00:00 EET 1970-10800000 - >应该是0,因为我们给00:00小时,其他时间元素保持默认.
//编辑
是的问题是使用时区修复此用途df.setTimeZone(TimeZone.getTimeZone("UTC")); 在解析之前.
我目前正在使用此堆栈expres,socket.io,sessionstore.我按照这里的文章http://www.danielbaulig.de/socket-ioexpress/.那么问题是我无法修改socket.io回调中的会话值.
快递方面的访问效果很好,每次刷新后项目都会增加.
app.get('/mysession', function(req, res) {
req.session.item++;
console.log(req.session);
res.render('session.jade', {
title: 'Sample title'
});
});
Run Code Online (Sandbox Code Playgroud)
在socket.io方面使用它没有,这是问题,也许我设置了错误的对象.
var io = io.listen(app);
io.sockets.on('connection', function(socket) {
var handshake = socket.handshake;
onlineCount++;
console.log('Well done id %s', handshake.sessionID);
handshake.session.item++;
console.log(handshake.session);
});
Run Code Online (Sandbox Code Playgroud)
这是桥码.
io.set('authorization', function(data, accept) {
if (data.headers.cookie) {
data.cookie = parseCookie(data.headers.cookie);
data.sessionID = data.cookie['express.sid'];
sessionStore.get(data.sessionID, function(err, session) {
if (err || !session) {
accept('Error', false);
} else {
data.session = session;
accept(null, true);
}
});
} else {
return accept('No cookie tansmitted', …
Run Code Online (Sandbox Code Playgroud) node.js ×7
javascript ×2
console ×1
event-loop ×1
express ×1
git ×1
java ×1
mercurial ×1
mongodb ×1
mongoose ×1
npm ×1
orm ×1
package ×1
postgresql ×1
pug ×1
sequelize.js ×1
session ×1
timestamp ×1