Tag: 表示

呈现基本的HTML视图?

我有一个基本的node.js应用程序,我试图使用Express框架来实现。 我有一个views文件夹,我有一个index.html文件。 但是在加载Web浏览器时收到以下错误。 错误:找不到模块'html' 以下是我的代码。 var express = require('express'); var app = express.createServer(); app.use(express.staticProvider(__dirname + '/public')); app.get('/', function(req, res) { res.render('index.html'); }); app.listen(8080, '127.0.0.1') 我在这里错过了什么?

使用Express 4.0上传文件:req.files未定义

我试图得到一个简单的file upload机制与Express 4.0的工作,但我一直在app.post正文req.files undefined 。 这是相关的代码: var bodyParser = require('body-parser'); var methodOverride = require('method-override'); //… app.use(bodyParser({ uploadDir: path.join(__dirname, 'files'), keepExtensions: true })); app.use(methodOverride()); //… app.post('/fileupload', function (req, res) { console.log(req.files); res.send('ok'); }); ..和随行的Jade代码: form(name="uploader", action="/fileupload", method="post", enctype="multipart/form-data") input(type="file", name="file", id="file") input(type="submit", value="Upload") 解 感谢下面的mscdex的响应,我已经转而使用bodyParser而不是bodyParser : var fs = require('fs'); var busboy = require('connect-busboy'); //… app.use(busboy()); […]

如何在Node.js的Express.js中获取GET(查询string)variables?

我们可以在Node.js的查询string中获取variables,就像我们在PHP中的$_GET中获取它们一样吗? 我知道在Node.js中,我们可以在请求中获取URL。 有没有一种方法来获取查询string参数?

计算组的平均值(或其他汇总统计)并分配给原始数据

我想计算分组variables(“组”)每个级别内的数值variables(“值”)的mean (或任何其他长度为1的摘要统计,例如, min , max , length , sum )。 汇总统计信息应分配给与原始数据具有相同长度的新variables。 也就是说,原始数据的每一行都应该有一个对应于当前组值的值 – 数据集不应该被折叠为每组一行。 例如,考虑组mean : 之前 id group value 1 a 10 2 a 20 3 b 100 4 b 200 后 id group value grp.mean.values 1 a 10 15 2 a 20 15 3 b 100 150 4 b 200 150

如何允许CORS?

我正在尝试在使用Express.js Web框架的Node.js应用程序中支持CORS。 我已经阅读了关于如何处理这个问题的Google小组讨论 ,并阅读了一些关于CORS如何工作的文章。 首先,我这样做了(代码是用CoffeeScript语法编写的): app.options "*", (req, res) -> res.header 'Access-Control-Allow-Origin', '*' res.header 'Access-Control-Allow-Credentials', true # try: 'POST, GET, PUT, DELETE, OPTIONS' res.header 'Access-Control-Allow-Methods', 'GET, OPTIONS' # try: 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept' res.header 'Access-Control-Allow-Headers', 'Content-Type' # … 这似乎并不奏效。 好像我的浏览器(Chrome)没有发送初始的OPTIONS请求。 当我刚刚更新资源块时,我需要提交一个跨源GET请求到: app.get "/somethingelse", (req, res) -> # … res.header 'Access-Control-Allow-Origin', '*' res.header 'Access-Control-Allow-Credentials', true res.header […]

错误:发送到客户端后无法设置标题

我是相当新的Node.js,我有一些问题。 我正在使用Node.js 4.10和Express 2.4.3。 当我尝试访问http://127.0.0.1:8888/auth/facebook时 ,我将被redirect到http://127.0.0.1:8888/auth/facebook_callback 。 然后我收到以下错误: Error: Can't render headers after they are sent to the client. at ServerResponse.<anonymous> (http.js:573:11) at ServerResponse._renderHeaders (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/patch.js:64:25) at ServerResponse.writeHead (http.js:813:20) at /home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/auth.strategies/facebook.js:28:15 at /home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/index.js:113:13 at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/strategyExecutor.js:45:39) at [object Object].pass (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/authExecutionScope.js:32:3) at [object Object].halt (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/authExecutionScope.js:29:8) at [object Object].redirect (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/authExecutionScope.js:16:8) at [object Object].<anonymous> (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/auth.strategies/facebook.js:77:15) Error: Can't set headers […]

XMLHttpRequest无法加载https:// www。 .com /

我有一个Grunt进程启动一个express.js服务器的实例。 直到现在,它开始提供一个空白页面,并且在Chrome(最新版本)的开发者控制台的错误日志中出现以下内容: XMLHttpRequest无法加载https:// www。[website] .com /否请求的资源上存在“Access-Control-Allow-Origin”标头。 原因' http:// localhost:4300 '因此不被允许访问。 什么阻止我访问页面?