Jump to content
McKay Development

How to get Express to show backpack in nodejs


Lonster_Monster

Recommended Posts

I am working on a site and want to get steam items with nodejsand express i understand how to get item inventory and i am using the get-steam-inventory npmmodule and not sure on why the backpack is not being generated in the express below is the price.js file i have for price.pug and in the pug file i call each item in items and cannot get the value of length any help would be appreciated

var express = require('express');

var router = express.Router();
//var pages = require('../pages/Pages.json');
//var quality = require('../public/730/quality.json')
var fs = require('fs');
var data;
var steamid;
var backpack;
var appid = 440;
const steaminventory = require('get-steam-inventory');

/* GET users listing. */
router.get('/', function(req, res, next) {
    // render template
	steamid = req.user.steamid
	var path = './public/json/'+steamid+'.json';
	checkFile(path);
    res.render('price', {user: req.user, items: req.backpack});
	console.log(backpack)
});
function checkFile(path) {
	try {
		if (fs.statSync(path)) {
			fs.readFile(path,"utf8", (err, backpack) => {
			  if (err) throw err;
			backpack = backpack
			});
		}
	} catch(err) {
		steaminventory.getinventory(appid, steamid, function(err, items){
		  if(err) {
			return console.log("Error, while getting user items. Please check settings or user inventory is hidden.");
		  } else {
			if (items){
				fs.writeFile(path, JSON.stringify(items.raw, null, 4), { flag: 'w' }, function (err) {
					if (err) throw err;
					console.log('\x1b[32m','The file has been saved!','\x1b[0m');
				});

			}
			checkFile(path)
		  }
		})
	}
}


module.exports = router;


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...