Home > other >  Why it comes a empty Line?
Why it comes a empty Line?

Time:11-05

I just want to make a JS Program where you can get Server Name, Server Players, Server Max Players etc. using a Custom CDN.

It dont comes a Error or something like that. Only a empty line.


const config = require("./conf.json");

console.log('test')

async() => {
    const IP = "164.132.226.166";
    console.log('IP definiert');
    const PORT = "22005";
    console.log('Port definiert');
    try {
        let req = await fetch("https://cdn.rage.mp/master/", {
        method: "GET",
    });
    console.log('Macht da was mit der CDN');
    let data = await req.json();
    let serverData = data[`${IP}:${PORT}`];
    let name = serverData.name;
    let gamemode = serverData.gamemode;
    let website = serverData.url;
    let currentPlayers = serverData.players;
    let peakPlayers = serverData.peak;
    let maxPlayers = serverData.maxplayers;
    console.log('Alles definiert');
    console.log(name, gamemode, website, currentPlayers, peakPlayers, maxPlayers);
    }
    catch(e) {
        console.error(e);
    }
}

CodePudding user response:

As @Bergi said, this is just defining the function. You can run it by making it a self-executing function, like so:

(async() => {
    // your code here
})();

CodePudding user response:

async () => {} is not an IIFE (Immediately Invoked Function Expression), so it doesn't run.

You should use:

const config = require("./conf.json");

console.log('test');

(async () => {
    const IP = "164.132.226.166";
    console.log('IP definiert');
    const PORT = "22005";
    console.log('Port definiert');
    try {
        let req = await fetch("https://cdn.rage.mp/master/", {
            method: "GET",
        });
        console.log('Macht da was mit der CDN');
        let data = await req.json();
        let serverData = data[`${IP}:${PORT}`];
        let name = serverData.name;
        let gamemode = serverData.gamemode;
        let website = serverData.url;
        let currentPlayers = serverData.players;
        let peakPlayers = serverData.peak;
        let maxPlayers = serverData.maxplayers;
        console.log('Alles definiert');
        console.log(name, gamemode, website, currentPlayers, peakPlayers, maxPlayers);
    } catch(e) {
        console.error(e);
    }
})();
  • Related