Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 02 2020 06:16
    @ljharb banned @frank-dspeed
  • Apr 27 2018 01:23
    @MylesBorins banned @fjeddy
  • Feb 24 2016 08:26
    @rvagg banned @jonathanenbe
Stephen James
@sjames1958gm
Make sure uploadFile is async
Montassar Ben Dhifallah
@Momentum-TN
It is
Stephen James
@sjames1958gm
My bad - you have to put async on the callback function async (req, res, next)
Montassar Ben Dhifallah
@Momentum-TN
thank you so much <3
it worked !
Stephen James
@sjames1958gm
@Momentum-TN Great!
Salkcid
@Salkcid
Hi! Are there any differences between development or production mode in Node.js itself? By that I mean, for example the error stack depth is smaller or more caching levels take place to optimize performance or something like that? If there are differences then where can I read about them?
Jordan Harband
@ljharb
node has no concept of "development mode" or "production mode"
1 reply
by convention, people use process.env.NODE_ENV and set it to "production", but node doesn't look at that.
Vlad Emelianov
@vemel
hello guys! I have created a CLI app to clone, update and share GItHub Actions across projects. Written in TypeScript and comes with a ready-to-use pack of workflows for Node.js projects. Please let me know if you find it useful https://github.com/vemel/github_actions_js
zillerium
@zillerium
any idea how to ensure the outcome from a promise is read - example below the bal is not set to the func calling the func -
async function getWalletBalance(walletId) {
  const coin = 'talgo';
  const basecoin = bitgo.coin(coin);
  // TODO: set your wallet Id here
  var bal ="";

  Promise.coroutine(function *() {
    bitgo.authenticateWithAccessToken({ accessToken: accessToken });

    const walletInstance = yield basecoin.wallets().get({ id: walletId });
    console.log('Wallet ID:', walletInstance.id());
    console.log('Current Receive Address:', walletInstance.receiveAddress());
    console.log('Balance:', walletInstance.balanceString());
    console.log('Confirmed Balance:', walletInstance.confirmedBalanceString());
    console.log('Spendable Balance:', walletInstance.spendableBalanceString());
    bal =  walletInstance.balanceString();
  })();

  return bal;
}
Vlad Emelianov
@vemel
maybe return promise itself as a second value?
zillerium
@zillerium
how is that done?
I thought promise.coroutine waited
Vlad Emelianov
@vemel
well, actually, returning bal makes no sense, it will be empty, so return a promise and resolve(bal)
zillerium
@zillerium
I will try now
Niko
@niko:chat.tgp.io
[m]
Do you need the generator/coroutine?
Vlad Emelianov
@vemel
i do not see a point to use generator as well
zillerium
@zillerium
the code is sample code for bitgo, I just wanted to send back the balance but the async fails.
bitgo is used for stablecoins
Vlad Emelianov
@vemel
  return new Promise(async resolve => {
    bitgo.authenticateWithAccessToken({ accessToken: accessToken });

    const walletInstance = await basecoin.wallets().get({ id: walletId });
    console.log('Wallet ID:', walletInstance.id());
    console.log('Current Receive Address:', walletInstance.receiveAddress());
    console.log('Balance:', walletInstance.balanceString());
    console.log('Confirmed Balance:', walletInstance.confirmedBalanceString());
    console.log('Spendable Balance:', walletInstance.spendableBalanceString());
    const bal =  walletInstance.balanceString();
    return bal;
  })();
smth like this
zillerium
@zillerium
does this help - const Promise = require('bluebird');
that is used now
I will try the resolve
Vlad Emelianov
@vemel
i updated the code
why do you use bluebird in this case?
zillerium
@zillerium
this is standard code from bitgo
they are a bit dated, they use v10
Vlad Emelianov
@vemel
never worked with it. maybe. i still do not understand why they used yield
zillerium
@zillerium
it states yield acts like await
Vlad Emelianov
@vemel
yet it forces you to use a generator
Vlad Emelianov
@vemel
since your func is async as well, you can just get rid of the promise
    await bitgo.authenticateWithAccessToken({ accessToken: accessToken }); // i assume, it is async as well?

    const walletInstance = await basecoin.wallets().get({ id: walletId });
    console.log('Wallet ID:', walletInstance.id());
    console.log('Current Receive Address:', walletInstance.receiveAddress());
    console.log('Balance:', walletInstance.balanceString());
    console.log('Confirmed Balance:', walletInstance.confirmedBalanceString());
    console.log('Spendable Balance:', walletInstance.spendableBalanceString());
    return  walletInstance.balanceString();
and this guarantees that your getWalletBalance func returns a string if everything goes well
zillerium
@zillerium
yes that all works. I just deleted the promise completely.
thank you for your suggestions @vemel
Vlad Emelianov
@vemel
no worries :) good luck with bitgo integration!
zillerium
@zillerium
all working now
Montassar Ben Dhifallah
@Momentum-TN

hey guys, hope you are all well.

I am working on sending an http request from angular to an API in the node server. I want to send a json object to the server and use it. I am stuck in this code:

Angular:

const headers ={ 'content-type': 'application/json'}
 body = { key1:   val1, key2: val2}
    this.http.post<any>('http://localhost:3000/send', body,{'headers':headers} ).subscribe(response => {
// do something
})

in node, I wrote this using express:

app.post('/send' , (req, res, next) => {
// do somthing with req
// send res
})

How can I send the json object correctly in angular? and how can I use it correctly in node?

Thanks in advance

Stephen James
@sjames1958gm

@Momentum-TN You'll want to include body-parser in your express app

app.use(bodyParser.json());

Then req.body will have the json sent in the body.

Lorenzo Sandini
@lsandini
Hello there, I am back with a basic question. My application is using shared variable in various scripts, and I decided to store them in a .json file that I "require" at the beginning of each script. Now I understand it is not best practice, and I read about the .env file that I could set up for that. Trouble is that I am writing my project in VSCode, and my host is WLS2 (or windows linux subsystem) where I installed ubuntu 20.04. Once ready, I transfer my scripts onto a DigitalOcean VM. In my dev environment, my .env file that I set up in my project folder is completely ignored and when I call process.env I see all kind of stuff unrelated to my own .env file. Any idea how I should do that, so that it works in my local dev environment, as well as on my VM in the cloud ?
Lorenzo Sandini
@lsandini
maybe some directions where I can read more about that ? I didn't find a clear explanation despite searching for quite a while
Lorenzo Sandini
@lsandini
whhhhh... (tumbleweeds rolling).
Jordan Harband
@ljharb
i'm not sure what vscode has to do with anything
nor WSL2 (that just means despite being on windows, you have a non-broken OS)
Ayush Raj
@yoayushraj99

maybe some directions where I can read more about that ? I didn't find a clear explanation despite searching for quite a while

https://www.npmjs.com/package/dotenv

Read the docs of dotenv npm package.

Aditya Khanna
@AdityaKhanna
Yup, dotenv is what you need.. stuff-unrelated-to-your-.env file is because process.env picks up the env variables of the shell you’re using to run the process. They should include some of the output of the printenv command from terminal
As @ljharb mentioned don’t worry about VS code + WSL2 setup. VS code is simply a remote text editor in your case.. the runtime environment is completed Ubuntu on wsl2
Lorenzo Sandini
@lsandini
ok thanks all, I'll need to re-read the dotenv documentation. I had found it, but for some obscure reason I thought it was unnecessarily complicated.