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

201
Visualizações
How to call node.js libraries from server.js?

I am new to node.js. I have an application angular front end and node.js server. And there is a js library that I am trying to get data.

What I am trying to do is user will press a button and pass data to server. Server will pass data to a node.js library and library will return data to server. Server will send back data to user.

I tried to call js library from angular front end as a script. But there are lots of errors because of webpack is higher than 5.

node.js file:


const Mam = require('@iota/mam')
const { asciiToTrytes, trytesToAscii } = require('@iota/converter')

const mode = 'private'
const provider = 'https://nodes.devnet.iota.org'
const sidekey= 'hf8685nfhfhjs9h8'
let mamState = Mam.init(provider)

const checkMam = async root=>{
  const result = await Mam.fetch(root, mode)
  result.messages.forEach(message => console.log('Fetched and parsed', JSON.parse(trytesToAscii(message)), '\n'))

return result.messages;
}
module.exports = { checkMam };

server.js file:


const express = require('express');
const MAM_listen = require("./MAM_listen");

const app = express(),
      bodyParser = require("body-parser");
      port = 3080;

const users = [];
const root ='YQKXWPSBRHZXEMDUMGEHVYJKSKZVNCIBEDPYMURKLRIOOYHBCRTGGOSFGPOVSHCXIXMKKSFJIAUL9XPJZ';

app.use(bodyParser.json());
app.use(express.static(process.cwd()+"/my-app/dist/angular-nodejs-example/"));

app.get('/api/users', (req, res) => {
  MAM_listen.checkMam(root).then((value) => console.log(value))
  res.json(users);
});

app.post('/api/user', (req, res) => {
  const user = req.body.user;
  users.push(user);
  res.json("user add");
});

app.get('/', (req,res) => {
  res.sendFile(process.cwd()+"/my-app/dist/angular-nodejs-example/index.html")
});

app.listen(port, () => {
    console.log(`Server listening on the port::${port}`);
});

I am getting this error when I am call (MAM_listen.checkMam) from app.get because the function is promise type. Is it another way to do what I am trying to do? How is this normaly done? Thank you

error

about 4 years ago · Juan Pablo Isaza
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