Tag: expression

通过Sequelize(Express / NodeJS)访问MySQL时出错

我正在尝试使用Sequelize。 我虽然想到了一些错误,但清除了其中的一些,但是我无法弄清楚。 项目结构: Project -Client -Server –models —index.js —Sid.js –router —routes —-signup.js —index.js app.js 我的configuration可变: "Lexstart": { "dbConfig": { "driver": "mysql", "user": "root", "database": "sid1", "password": "sid1", "host": "127.0.0.1", "port": "3306" } } 我的模特/ index.js: var fs = require("fs"); var path = require("path"); var Sequelize = require('sequelize'); var config = require('config'); // we use node-config […]

脚本没有被调用

我正在使用ExpressJS。 我的脚本或CSS将不会加载。 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"/> <meta name="apple-mobile-web-app-capable" content="yes"/> <meta name="apple-mobile-web-app-status-bar-style" content="black"/> <title>Customer Info</title> <link rel="stylesheet" href="/stylesheets/testing.css" type="text/css" media="screen" charset="utf-8"/> <script type="text/javascript" src="/javascripts/jquery-1.9.1.js"></script> <script src="/javascripts/jquery-ui-1.10.2.custom.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript" src="/javascripts/testing.js"></script> </head> <body> //body contents </body> </html> 我知道问题不在于地点。 当我以快速渲染这个EJS视图时,没有任何脚本正在加载。 我不明白为什么它会为几乎相同的观点工作,但不是这个。 有任何想法吗?

正则expression式不能读取HTML文件

首先,我知道大多数RegExp问题。 这不是其中之一,“请写我的代码”的问题。 我的困惑在于,我的RegExp在regexr上工作,在chrome的开发工具中轮询document.body.textContent ,但是在io.js中读取后,不在HTML文件上。 io.js是版本1.5.1,在Windows 8上运行 为什么它会在这两个地方上市,但不是在io.js? 我没有考虑到io.js读取文件的问题吗? 我的RegExp应该与下面的链接中的“ @{each ___->___} text and line breaks @{/each} ”匹配,但是它会返回null 这是我正在尝试使用: http : //regexr.com/3aldk 正则expression式: /@\{each ([a-zA-Z0-9->.]*)\}([\s\S]*)@\{\/each}/g JS(例子): fs.readFile('view.html', {encoding:'utf8'}, function(error, html) { console.log(html.match(myRegExp)); // null }); HTML: <!doctype html> <html> <head> <title>@{title}</title> </head> <body> <h1>@{foo.bar}</h1> <p> Lorem ipsum dolor sit amet, @{foo.baz.hoo} </p> @{each people->person} <div> <b>@{person.name}:</b> […]

在Express或与Node.js连接,有没有办法在内部调用另一个路由?

所以,我有这样的设置(在Express中): app.get('/mycall1', function(req,res) { res.send('Good'); }); app.get('/mycall2', function(req,res) { res.send('Good2'); }); 如果我想让一个聚合函数调用/mycall1和/mycall2而不重写代码/mycall1用/mycall1和/mycall2代码? 例如: app.get('/myAggregate', function (req, res) { // call /mycall1 // call /mycall2 });

nodejs强大不会触发任何事件

我在express3.x上使用强大的 app.post "/up",(req,res)-> formidable = require('formidable') form = new formidable.IncomingForm() form.uploadDir = __dirname + "/uploads" form.encoding = 'binary' form.addListener 'file',(name,file) -> #write file console.log('file uploaded') return console.log('$$$$$$$$$$$') form.addListener 'end', -> console.log('end') res.end() return console.log('@@@@@$$$$') form.parse req,(err,fields,files)-> console.log('parse') console.log(err) if(err) return console.log('######') return 和上传表单是 block content :coffeescript $ -> formData = new FormData() xhr = new […]

优化Node.js内存消耗

我在Node.js,Express和MongoDB中编写了一个简单的cms。 我打算为每个站点运行不同的Node.js进程。 问题是,启动后,这个过程需要大约90米的内存,对我来说太大(8个站点需要所有的服务器内存)。 此内存是在第一次连接到站点后进行的,其他连接不会影响内存。 有没有一个指导或“最佳实践”的列表来优化这种内存使用情况? 我试图追踪内存分配与process.memoryUsage()或类似的function,但这并不简单。 不是内存泄漏或类似的问题,因为在第一次连接后内存使用不会增长,所以可能的优化可能是加载更less的模块或做不同的事情…

在Node.js(Express)Facebookcanvas应用程序中获取signed_request

有什么办法如何获得和parsingNode.js Facebook页面标签应用程序中的signed_request? 我需要知道页面ID,如果用户喜欢的网页…

Node.js / express:立即响应客户端请求并在nextTick中继续执行任务

我想将服务器高消耗CPU任务与用户体验分开: ./main.js: var express = require('express'); var Test = require('./resources/test'); var http = require('http'); var main = express(); main.set('port', process.env.PORT || 3000); main.set('views', __dirname + '/views'); main.use(express.logger('dev')); main.use(express.bodyParser()); main.use(main.router); main.get('/resources/test/async', Test.testAsync); main.configure('development', function() { main.use(express.errorHandler()); }); http.createServer(main).listen(main.get('port'), function(){ console.log('Express server app listening on port ' + main.get('port')); }); ./resources/test.js: function Test() {} module.exports = Test; […]

玉模板引擎:HTML美化?

我在Node.js上使用ExpressJS的玉石模板引擎。 它用单行输出一个html。 根本没有缩进。 我找不到任何美化的选项。

sequelize .create不是函数错误

我得到Unhandled rejection TypeError: feed.create is not a function错误,我不明白为什么会发生。 这里有什么问题? 这是我的代码。 由于我无法在routes / index.js中访问feedvariables,因此我可能不会在这里做一些非常基础的工作。 如果我添加module.exports = feed; 到我的模型文件,我可以达到它,但我有多个模型,所以如果我添加额外的模型饲料,他们覆盖它。 db.js var Sequelize = require('sequelize'); var sequelize = new Sequelize('mydatabase', 'root', 'root', { host: 'localhost', dialect: 'mysql', port: 8889, pool: { max: 5, min: 0, idle: 10000 }, define: { timestamps: false } }); var db = {}; […]