Tag: 得到

Express控制台显示许多请求

对于每个页面加载应该如何工作,我有点困惑。 这是一个正常的日志状态写在页面中的所有静态资产,或者它应该只显示一个请求的视图?

与头节点js的GET调用

这是我做一个REST调用的代码。 我已经尝试与POSTMANrest电话和url和标题是好的。 但是对于节点j,我无法做到这一点 我没有在这里给出真正的API密钥和url /** * HOW TO Make an HTTP Call – GET */ // options for GET var optionsget = { host : 'abcd.com:80/edwde/wedwed/', // here only the domain name // (no http/https !) //port : 443, //path : '/youscada', // the rest of the url with parameters if needed headers : getheaders, […]

发送ajax获取请求到节点,响应是未定义的

我有一个运行单个网页的节点服务器。 该页面有一个联系表单和一个发送button。 如果我点击发送,下面的代码将运行: $('.contactsend').click(function(){ $.ajax({ method: "GET", url: "http://127.0.0.1:3000/contact", dataType: "jsonp" }) .done(function(data) { alert( data ); }) .fail(function() { alert( "error" ); }) .always(function() { alert( "complete" ); }); }) 到目前为止,这似乎确定,页面已达到。 这就是中间件所做的事情: router.get('/', function(req, res, next) { res.send({test:'test'}) //res.send('test') }); 发送完毕后,网页显示如下信息: Uncaught SyntaxError: Unexpected token : 如果我不发送json ,而是string,消息就像 Uncaught ReferenceError: test is not defined

Node.js / Express:通过ajax下载文件

我试图通过GET ajax调用dynamic请求一个文件下载。 我有以下客户端代码: $(function() { $('#submit').click(function() { $.ajax({ type: "GET", url: "/download/" + "filename", dataType: "json", contentType: "application/json", complete: function() { console.log('Complete'); }, success: function() { console.log('Success'); }, error: function() { console.log('Error'); } }); }); }); 在节点服务器上,我也有以下行(请注意,我不知道这是否是正确的方法) app.get('/download/:filename', function(req, res) { console.log(req.params); res.write(fs.readFileSync(__dirname + "/../public/javascripts/main.js", 'utf8')); }); 所以我想实际上下载该JavaScript文件(最终dynamic)。 我将如何去做这个正确的? 东西告诉我,我需要指定标题/内容types。

基本的node.js代码不工作

服务器正在启动,没有任何错误,但url被击中,显示没有应用程序运行。 url: link_To_Server 我的代码: var express= require('express'); var app=express(); app.get('/', function(req, res, next) { console.log('home'); res.send(200); res.end('getting requests'); }); console.log('server started');

在Heroku上运行Node.js应用程序时出错

我在尝试在Heroku上运行一个简单的Node.js应用程序时遇到了令人沮丧的“错误”。 Heroku本身并没有报告错误 – 应用程序已经启动(不会崩溃,不会显示“Hxx”代码); 我得到的是这样的: heroku[router]: at=info method=GET path=/index.html host=realsheek.herokuapp.com fwd="24.63.82.165" dyno=web.1 connect=0ms service=4ms status=404 bytes=33 当我从浏览器运行应用程序,它说Cannot GET 。 我不知道它想要什么。 我的应用程序是使用Mozilla的SocialAPI的SocialProvider的testing平台。 该应用程序本身是从https://github.com/mixedpuppy/socialapi-demo演示的版本。 有几个bug被修复了,否则这个和这个demo是一样的(我用的是只修复了bug的repo)。 我有一个index.html页面,它安装了SocialProvider,在这个时候服务器端的应用程序踢了,并做了其余的魔术。 它在localhost上运行良好,但是当我推到Heroku时,它失败了。 git push没有问题报告(只是通常的“没有自述数据”的警告)。 我难以理解,因为我只是看不到它试图获得什么; 显然404错误表明缺less一个页面,但该应用程序不会调用任何HTML页面,并且所需的一切都存在(如我在localhost运行确认)。 我意识到,这不是很多,没有看到实际的应用程序,也不知道它正在做什么。 而没有实际的错误报告 – 只是一个404状态,显然可以是任何东西。 但是我现在很难受,所以如果有人有什么见解或者build议的话,我会很感激。

如何在Node JS中的本地variables中存储GET请求的响应

我知道如何使用request模块对URL进行GET请求。 最终,代码只是在产生它的命令shell中打印GET响应。 如何将这些GET响应存储在本地variables中,以便在程序中的其他位置使用它? 这是我使用的代码: var request = require("request"); request("http://www.stackoverflow.com", function(error, response, body) { console.log(body); });

Node.JS函数返回http响应值

我需要调用一个使http请求的函数,并通过callback函数返回给我的值。 但是,当我尝试我不断收到空响应。 任何帮助? 这是我的代码: var url = 'www.someurl.com' makeCall(url, function(results){return results}) makeCall = function (url, results) { https.get(url,function (res) { res.on('data', function (d) { resObj = JSON.parse(d); results(resObj.value) }); }).on('error', function (e) { console.error(e); }); }

Heroku nodejs教程无法在本地获取/冷却

下面是我的package.json文件的依赖关系,我添加了“cool-ascii-faces。然后我需要更新我的index.js文件来获取/ cool页面,这样每次刷新时我都会看到一个ascii的脸。我得到一个404错误,它说'不能GET /酷' "dependencies": { "ejs": "2.3.3", "express": "4.13.3", "cool-ascii-faces": "~1.3" } 下面是我的index.js文件,调用声明很酷 var cool = require('cool-ascii-faces'); var express = require('express'); var app = express(); app.set('port', (process.env.PORT || 5000)); app.use(express.static(__dirname + '/public')); // views is directory for all template files app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); app.get('/cool', function(request, response) { response.render('pages/index') }); app.get('/cool', function(request, […]

Node.js:GET请求返回404 Not Found

正在使用Node.js和Express创build一个REST API。 服务器在localhost:xxxx启动,但localhost:xxxx/bits返回404 Not Found错误。 var express = require('express'); var app = express(); app.get('/bits', function(req, res) { console.log("Bits called"); }); app.get('/bits/:id', function(req, res) { console.log("Bits ID called"); }); app.listen(xxxx); console.log('Listening on port xxxx.'); 帮帮我?