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
Tim
@tim:schumacher.im
[m]
Greetings from the Matrix 😀
codesleuth
@codesleuth:matrix.org
[m]
Yes hello! Tank cut the hard line and here we all are
Jakub Barczyk
@jakubbarczyk
I've written a short poem for all the Node people out there... ehm!
Matrix is green and so is Node
I can't express how I love to code!

:-)
Guilherme C. Souza
@GCSBOSS

Hi, everyone! I don't mean to annoy you. Would you help me answering a few (9) simple questions about your dev env setup?
https://docs.google.com/forms/d/e/1FAIpQLSd7E-S207EQ7YwsC6rDzW8fxAgyCqTiRRRULysqZQbWNH_biA/viewform?usp=sf_link
Very much appreciated!

Also, let me know if by any chance this is agains the rules.

Rajpal Chauhan
@raj-here

Hi All,

Can someone please help me to write a synchronized function in Node.

What I want, when multiple request trying to access same function it should be locked for one until the data has not been processed within that function.

Here is the my code:
nodejs/help#3177

NikitaBazhenovb
@NikitaBazhenovb
Hi
You should use the callback function to do that
Rajpal Chauhan
@raj-here
Hi @NikitaBazhenovb,
Nope it is not in that case too
NikitaBazhenovb
@NikitaBazhenovb
um, could you please let me know more correctly?
in my case , it works using callback function
First, you need to make callback function and in it, you should use the functions.
Rajpal Chauhan
@raj-here
const updateData = async (index: number): Promise<void> => {
const currentVersion = await getCurrentVersion();
const latestVersion = currentVersion + 1;
const s3FileName = "file_" + latestVersion + ".pdf";
const seResult = await uploadFileToS3(currentVersion, s3FileName);
console.log("S3 Result", seResult)
setCurrentVersion(latestVersion);
console.log("RequestNumber: ", index, ", LastVersion: ", currentVersion, ", LatestVersion: ", latestVersion);
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
}
NikitaBazhenovb
@NikitaBazhenovb
app.get('/test', makecallback(controller)
});
and in controller you should define the response code.
Rajpal Chauhan
@raj-here
Ahhh, I hear you
NikitaBazhenovb
@NikitaBazhenovb
does that make sense?
Rajpal Chauhan
@raj-here
Let me check and back to you
NikitaBazhenovb
@NikitaBazhenovb
Okay
Rajpal Chauhan
@raj-here
@NikitaBazhenovb Thanks for your help
NikitaBazhenovb
@NikitaBazhenovb
Welcome
Rajpal Chauhan
@raj-here

Hi @NikitaBazhenovb,
Can you please gimme a example please.

I'm little bit confused how to use it.

NikitaBazhenovb
@NikitaBazhenovb
yeah,,, could you let me know your source project?
Rajpal Chauhan
@raj-here
Yes, sent you in private chat
mohit-techdoodles
@mohit-techdoodles

Hi,i am trying to get only those emails which are received as email reply send by my system.for more specific i am sending email with attachment .and receiver replies to that email with attachment.

I want history of email in my system which shows which attachment is received against which email. for example if i have send email to pearson B.Pearson B will reply to that email.i want history of this.
I am able to send and receive email.But the issue is that i am getting all email fetched betwwen a and b(I want only those email which is send as reply of particular email).Below i gave given code to fetch email.

var mailListener = new MailListener({
              username: "******",
              password: "******",
              host: "imap-mail.outlook.com",
              port: 993, // imap port
              tls: true,
              connTimeout: 10000, // Default by node-imap
              authTimeout: 5000, // Default by node-imap,
              tlsOptions: { rejectUnauthorized: false },
              mailbox: "INBOX", // mailbox to monitor
              searchFilter: [ 'UNSEEN', ['FROM', req.params.email] ], // the search filter being used after an IDLE notification has been retrieved , 
              markSeen: false, // all fetched email willbe marked as seen and not fetched next time
              fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
              mailParserOptions: {streamAttachments: true}, // options to be passed to mailParser lib.
              attachments: true, // download attachments as they are encountered to the project directory
              attachmentOptions: { directory: "attachments/" } // specify a download directory for attachments
        });

        mailListener.start();

        mailListener.on("server:connected", function(){
          console.log("imapConnected");
        });

        mailListener.on("error", function(err){
          console.log('hello');
        });

        mailListener.on("mail", function(mail, seqno, attributes){
            console.log(seqno)
            let attachments = [];
            var attachment = mail.attachments;
            if(attachment) {
                for(var i = 0, len = attachment.length; i < len; ++i){
                    attachments.push(attachment[i].fileName);
                }
            }
            passDatatoPage(mail, attachments);
            mailListener.stop();
        }) 

        mailListener.on("attachment", function(attachment){
            let filepath = './public/attachment/receive/';
            let output = fs.createWriteStream(filepath + attachment.fileName);
            attachment.stream.pipe(output).on("end", function () {
                console.log("All the data in the file has been read");
            }).on("close", function (err) {
                console.log("Stream has been cloesd.");
            });  
        });


        function passDatatoPage(mail, attachments) {
            var sender = mail.to[0].address;
            var senderName = mail.from[0].name;
            var reciver = mail.from[0].address;
            const date = moment(mail.date).format('LL');
            var subject = mail.subject;
            var message = mail.text;
            //console.log(attachments);
            var result = attachments.map(function(val) {
                return val;
            }).join(',');
            var attachmentArr = result.split(',');
            console.log(attachmentArr)
            res.render('email-reply', { title: 'Email Reply', to: sender, senderName: senderName, from: reciver, date: date, subject: subject, msg: message, attachments: attachmentArr});
        }

    });

May I know what is wrong with my code? please provide possible solution in this code or provide way how i achive my task. Thanks in advance.

2 replies
GeorgePals
@GeorgePals

Hello!
I have a very (?) strange issue here.
If I do:

var buf = Buffer.from('fhqwhgads', 'utf8');
console.log("Testing: " + buf)

I get: Testing: fhqwhgads
while, if I do:

console.log(Buffer.from('fhqwhgads', 'utf8'));

then I get the correct output: <Buffer 66 68 71 77 68 67 61 64 73>

Any ideas?
Thanks!

Tim
@tim:schumacher.im
[m]
@GeorgePals: What gives buf.toString()? Because that is what you propably get when concenating with string
GeorgePals
@GeorgePals

@GeorgePals: What gives buf.toString()? Because that is what you propably get when concenating with string

Hello Tim,

var buf = Buffer.from('fhqwhgads', 'utf8');
console.log("Testing: " + buf.toString())

Output: Testing: fhqwhgads

Am I missing something?

4 replies
Zerka1982
@Zerka1982
Hello guys,
Anybody here is familiar with Vue js ?
I am using Materialize css, I ve imported it, but it seems it has no impact
image.png
TheColdPot
@TheColdPot
Hello guys
I want clear node.js history, but I tried Alt+F7 and .clear, but they all not work. What should I do if I want to clear its history?
Jordan Harband
@ljharb
/clear?
TheColdPot
@TheColdPot
.clear is just a alias for .break
Jordan Harband
@ljharb
actually wait, what do you mean. you want to clear the repl history?
TheColdPot
@TheColdPot
yes
Jordan Harband
@ljharb
the node repl history is persistent
like, it lives beyond one invocation of node
TheColdPot
@TheColdPot
OK
Jordan Harband
@ljharb
which, of course, means it's stored in a file. so you can look at ~/.node_repl_history and clear it if you like
TheColdPot
@TheColdPot
Thanks!
Guilherme C. Souza
@GCSBOSS
Hello, fellows! How memory leaky are dangling awaits?
let p = new Promise(done => console.log('INSIDE'));
console.log('BEFORE');
await p; // Never resolving; but program continues to run (e.g listening to requests etc...)
console.log('AFTER');
3 replies
Enes Baytemir
@enesbytmr
Hi Guys
i need to learn what is the best way to learn nodejs
1 reply
Jordan Harband
@ljharb
@gcsboss no different than sticking a .then on p
Jakub Barczyk
@jakubbarczyk
@GCSBOSS read up about Promise in MDN docs. You're not calling the done function. It won't budge.
Stephen James
@sjames1958gm
I think that that is the point. If the promise never resolves, how much memory is ‘leaked’. But Jordan’s point is valid try and see.
Guilherme C. Souza
@GCSBOSS
@ljharb
Though the issue is not just in having a callback but in never resolving. The handler will never be GCed, correct?
Say you get 10k requests that trigger that code.
Jakub Barczyk
@jakubbarczyk
@enesbytmr be sure to check the publish date of any articles or tutorials you will come across... Learn from the latest sources.