本文介绍了ReferenceError:应用程序未在 Node.js 中定义 - SteamWebAPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

呃,我关于 API 的第三个问题仍然无法按照我想要的方式工作......无论如何,我有两个文件:app.jsindex.html.

我的index.html是简单的形式:

 <html lang="zh-cn"><头><meta charset="UTF-8"><title>Steam</title><身体><表格>Steam 用户 ID:<br><input type="text" name="steamid"><br><input type="submit" value="Pošalji"></表单></html>

表单正在获取 Steam 用户 ID 和提交按钮,以提交此表单.

我的app.js:

//快递var express = require('express');var server = express();//SteamWebAPIvar SteamWebAPI = require('steamwebapi').SteamWebAPI;SteamWebAPI.setAPIKey('7DB297EBF0D0FC352539B4AF9C7C850B');//渲染 - 表单server.get('/user_id', function(req, res) {app.render('form', function(err, html) {如果(错误)返回 res.send(err);别的返回 res.send(html)});});//路由-表单server.post('/user_info', function(req, res) {var _userID = req.body.userId;//变量 - SteamWebAPISteamWebAPI.getRecentlyPlayedGames(_userID, 5, function(req, res) {返回 res.json(response.response.games);});});//本地主机server.listen(3000,函数(){console.log('服务器:3000');});

如果我错了,有人纠正我:

-在我需要 express 和 steamwebapi 之后,我从表单中获取信息(在这种情况下是 Steam id),- 然后这个变量 _userID 等于 req.body.userId; 我不知道为什么......反正......我得到的错误是:**ReferenceError: app is not defined**

有人可以帮我解决这个问题吗?这个节点是不是太难了?喜欢,很简单.用户在表单中输入 id,服务器获取表单?并以 json 格式返回?我做错了什么???

PS:做个简单的方法,当我输入Steam ID时,我进入console.log游戏:例如CS:GO...有没有办法显示为图标?显然我不能在控制台中,所以我需要使用 angular、ember 或什么?谢谢各位

解决方案

在使用 app 变量前添加:

var app = express();

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.

My index.html is simple form:

    <!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>

Form is getting Steam User ID and submit button, to submit this form.

My 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:

-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**

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: Doing simple way, when I enter Steam ID, I get in console.log game: CS:GO for example...Is there way to display as icon? Obviously I cannot in console so I need to use angular, ember, or what? Thx folks

解决方案

Just add this before using app variable:

var app = express();

这篇关于ReferenceError:应用程序未在 Node.js 中定义 - SteamWebAPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 05:50