Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

403
Visualizações
Serverless ewelink api

I've been trying to make ewelink-api to work on a web browser directl and not as "node script" I've followed the directions stated here: https://ewelink-api.vercel.app/docs/demos/serverless So i made the following html file:

<!DOCTYPE html>

<html>
  <head>
    <title>
        Test
    </title>
  </head>

  <body>
    <div id="demo"><div>
    
    <script>
      document.getElementById("demo").innerHTML = "Hello JavaScript!";
      //const ewelink = require('ewelink-api');
      
      /* first request: get access token and api key */
      (async () => {
        const connection = new ewelink({
          email: 'myemail@gmail.com',
          password: 'mypassword',
          region: 'eu',
        });
        const login = await connection.getCredentials();
        const accessToken = login.at;
        const apiKey = login.user.apikey
        const region = login.region;
      })();
      
      /* second request: use access token to request devices */
      (async () => {
        const newConnection = new ewelink({
          at: accessToken,
          region: region
        });
        const devices = await newConnection.getDevices();
        console.log(devices);
      })();
    </script>
  </body>
</html>

And i was expecting to see some devices logged to console, but instead i get this error:

Uncaught (in promise) ReferenceError: ewelink is not defined

I've tried to add this line of code at the beggining:

const ewelink = require('ewelink-api'); but then i get this error:

Uncaught ReferenceError: require is not defined

Can anyone help me? Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

require is for Node.JS (as phuzi states) , import is a Javascript/ECMAScript (for browsers) standard.

see https://fjolt.com/article/javascript-export-import-node-js

but 'ewelink-api' and ev. dependents may also uses require,
so you had to replace all, maybe RequireJS helps

see also Client on Node.js: Uncaught ReferenceError: require is not defined

btw: the two async-calls should (must) be nested to be executed in sequence, here they are executed concurrently, so accessToken ... will be undefined in newConnection

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda