dajk / hltv-api

DEPRECATED: An unofficial JSON api for popular CS:GO website hltv.org. Check available methods on https://hltv-api.vercel.app/
http://npm.im/hltv-api
MIT License
277 stars 59 forks source link

Node.js ES6 Modules not supported? #7

Closed PPBWoodBoy closed 6 years ago

PPBWoodBoy commented 6 years ago

Hi and first of all thank you for this API.

I´m trying to get it running. But every time im running "node index.js" in your demo-app folder for example, nodejs says that it doesnt understand the token "import".

After a bit of research I found out that Nodejs doesn´t support ES6 Modules like "import" yet.

Is there a way to get it running? And will there be a method to get the Kills, deaths, assist, headshots etc. from the players of a match?

Greetings.

dajk commented 6 years ago

Hi @TomHaupt

Thanks for sharing your experience, I really appreciate it.

There is still work in progress and project is in early stage and I know should be documented better. Just recently I created demo-app, so you can have a look how would be some simple example.

So it's true, Node does not support ES6, but you can use babel and necessary plugins and then use babel-node to start the app like here, or you can use CommonJS module with require, and create simple api like following:

const express = require('express');
const HLTV = require('hltv-api');
const app = express();

app.get('/', function(req, res) {
  HLTV.getNews(function(news) {
    return res.json(news);
  });
});

app.get('/results', function(req, res) {
  HLTV.getResults(function(results) {
    return res.json(results);
  });
});

app.listen(3000, function() {
  console.log('Listening on port 3000...');
});

Then just start node index.js script, open localhost:3000 and you'll see news json or /results for latest results.

About match overview api and all statistics should be these days when I find time for that. I already created some tasks #2, #3 but there will be more.

Everyone are invited to try this module and write suggestions so I can clearly know what people need. I will definitely put some of this stuff into README so that everyone can use it just by following steps. Also contributions are welcome at any time.

I'll close this issue for now but feel free to reopen if you need any further help.

Best

PPBWoodBoy commented 6 years ago

Nice! Thank you! :) 👍