ReferenceError: app is not definied in Node.js - SteamWebAPI

不羁岁月 提交于 2020-01-07 03:40:14

问题


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


回答1:


Just add this before using app variable:

var app = express();


来源:https://stackoverflow.com/questions/35736053/referenceerror-app-is-not-definied-in-node-js-steamwebapi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!