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

2019-09-06 16:28发布

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条回答
劫难
2楼-- · 2019-09-06 16:34

Just add this before using app variable:

var app = express();
查看更多
登录 后发表回答