ReferenceError:应用程序未在Node.js中定义-SteamWebAPI [英] ReferenceError: app is not definied in Node.js - SteamWebAPI
问题描述
嗯,关于API的第三个问题仍然无法按照我想要的方式进行.无论如何,我有两个文件: app.js 和 index.html .
Eh, my third question about API and still cannot manage to work it the way I want... Anyways, I have two files: app.js and index.html.
我的 index.html 是简单形式:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Steam</title>
</head>
<body>
<form>
Steam User ID: <br>
<input type="text" name="steamid"><br>
<input type="submit" value="Pošalji">
</form>
</body>
</html>
表单正在获取Steam用户ID和提交按钮,以提交此表单.
Form is getting Steam User ID and submit button, to submit this form.
我的 app.js :
//Express
var express = require('express');
var server = express();
//SteamWebAPI
var SteamWebAPI = require('steamwebapi').SteamWebAPI;
SteamWebAPI.setAPIKey('7DB297EBF0D0FC352539B4AF9C7C850B');
//Render - Form
server.get('/user_id', function(req, res) {
app.render('form', function(err, html) {
if(err)
return res.send(err);
else
return res.send(html)
});
});
//Route - Form
server.post('/user_info', function(req, res) {
var _userID = req.body.userId;
//Variable - SteamWebAPI
SteamWebAPI.getRecentlyPlayedGames(_userID, 5, function(req, res) {
return res.json(response.response.games);
});
});
// Localhost
server.listen(3000, function() {
console.log('Server: 3000');
});
如果我错了,请纠正我:
Someone correct me if I'm wrong:
-在我需要express和steamwebapi之后,我从表格中获取信息(在这种情况下为Steam ID),
-那么此变量_userID等于req.body.userId;
,我不知道为什么...反正...得到的错误是:**ReferenceError: app is not defined
**
-after i require express and steamwebapi, i'm getting informations (in this case steam id) from form,
- then this variable _userID is equal to req.body.userId;
and i dont know why...anyways...error im getting is: **ReferenceError: app is not defined
**
有人可以帮我吗?这个节点太难了吗?就像,这很简单.用户以表格形式输入ID,服务器获取表格?并以json格式返回?我做错了什么?
Can someone help me with this? Is this Node too hard? Like, It's simple. User enter id in form, server getting form? and returning in json format? What I'm doing wrong???
PS:做一个简单的方法,当我输入Steam ID时,我进入console.log游戏:例如CS:GO ...有没有办法显示为图标?显然,我无法在控制台中使用,所以我需要使用角度,余烬或其他功能? Thx乡亲
推荐答案
只需在使用 app 变量之前将其添加:
Just add this before using app variable:
var app = express();
这篇关于ReferenceError:应用程序未在Node.js中定义-SteamWebAPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!