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

76
Visualizações
How to return values from main function in js code created by dart2js

I have dart code that returns a string when it is ran

main(){
print("hello");
 return "hello";
}

Now i need to call this from js so i used dart2js to convert it to js.

How i call it from a node.js application:

var sudokuLib = require('./sudoku-lib');
console.log(require('./sudoku-lib'));

I am aware of the large amount of code created by dart2js and it is not a problem since whenever i run the converted js file or the above js code, hello is being printed in the console. But the problem is that I want the returned value to be stored in a variable in my js code, since i will be using the value in my node application.

Is there any way to do this??

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

0

I will assume that your dart code is now js code and runing fine :

For exemple like this sudoku-lib.js :

function main() {
    return "Hello"
}

// add the code below
module.exports = { main };

in a new js file "file.js" you can simply write :

const lib = require("./sudoku-lib");
// store it in result var
const result = lib.main();
console.log(`The result is: ${result}`);

Ref node-modules-import-and-use-functions-from-another-file

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