Lonster_Monster Posted December 4, 2018 Report Share Posted December 4, 2018 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; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.