These are chat archives for FreeCodeCamp/HelpJavaScript

28th
Mar 2018
Greg Duncan
@GregatGit
Mar 28 2018 00:07
@sjames1958gm I had figured it out but it looks so much better using es6 with lodash
Stephen James
@sjames1958gm
Mar 28 2018 00:09
@GregatGit :+1:
Nate Mallison
@NJM8
Mar 28 2018 00:33
Hey all, just looking for some final feedback or testing on my calculator, thanks! https://www.natethedev.com/FreeCodeCampFrontEndProjects/calculator/
I was thinking about adding a delete button
well, a back button
Greg Duncan
@GregatGit
Mar 28 2018 00:46
@NJM8 Nice work - looks great and works. I would use a 'x' instead of *
Nate Mallison
@NJM8
Mar 28 2018 00:48
Thanks
yeah I guess * is really an exponenet
It just looks so different from the other symbols
Greg Duncan
@GregatGit
Mar 28 2018 00:53
the app has great style to it - well done
Nate Mallison
@NJM8
Mar 28 2018 00:55
the x does look better once I make the other symbols larger, thanks! @GregatGit
CamperBot
@camperbot
Mar 28 2018 00:55
njm8 sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 900 | @gregatgit |http://www.freecodecamp.org/gregatgit
abraham anak agung
@padunk
Mar 28 2018 02:55
@NJM8 nice design, and it works great, but have some trouble working with plus/minus button cause it not showing anything when you click it.
Ken Haduch
@khaduch
Mar 28 2018 03:59

@NJM8 - I started some testing of your calculator just with random operations. I find one that doesn't seem to complete, if I enter 3 - 6 = it doesn't present a result, and reports an error in the console: Uncaught TypeError: Cannot read property 'toFixed' of undefined at executeInput (scripts.js:39) at HTMLDivElement.button.addEventListener.event (scripts.js:192)

That's one thing, at least, I figured that I would report it. But here's another one that I was expecting to work - performing a calculation that is successful like 7 x 8 = gives the result 56. I was expecting to be able to continue to add + 3 but it cleared the result, or didn't continue to use the previous result in the calculation. That must be the way that you implemented it, but a regular feature of real calculators that I have used allows you to continue the calculation using that result that you just obtained just by continuing a math operation.

I do like the style and look of your calculator - very easy to read and I like the buttons outline.

Nate Mallison
@NJM8
Mar 28 2018 13:07
@padunk thanks. the plus/minus is a toggle and will enter a negative number on the next number input, I guess it would make more sense just to add the negative symbol and append the number to it. I'll add that in
CamperBot
@camperbot
Mar 28 2018 13:07
njm8 sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 481 | @padunk |http://www.freecodecamp.org/padunk
May Kittens Devour Your Soul
@diomed
Mar 28 2018 13:09

does any1 know why in this pen

        {
icon: "m-book",
name: "Martin Dressler: The Tale of an American Dreamer",
user: "Steven Millhauser",
          year: 1997
        },

name won't show?

Nate Mallison
@NJM8
Mar 28 2018 13:10
@khaduch thanks, wow, a fail on a simple calculation! haha. I'll into it, the input parser is failing somehow on just subtraction, it was working before so that must be a feature implementation bug. :smile:
CamperBot
@camperbot
Mar 28 2018 13:10
njm8 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3829 | @khaduch |http://www.freecodecamp.org/khaduch
Nate Mallison
@NJM8
Mar 28 2018 13:10
It's also a good point about the continued calculation, I will implement it
Matej Bošnjak
@mbosnjak01
Mar 28 2018 13:11
@diomed because it's not inside items array as far as I can see
@diomed oh right, name doeasn't show up there :|
@diomed When I put a name as "Martin Dressler" without the "The Tale of an American Dreamer", it shows. not sure why is that tho
May Kittens Devour Your Soul
@diomed
Mar 28 2018 13:15
maybe it has something to do with : ?
Matej Bošnjak
@mbosnjak01
Mar 28 2018 13:15
@diomed I got it, it goes somewhere down, it's still there in html ... I guess name is too long and it breaks down
if you set oferflow on that particular field just for test I guess you'll be able to scroll down to it
also if you set display:inline you'll be able to see it, but not full name, word Dreamer will be hidden because - name is too long, or, field is too short ... changes should be made there
May Kittens Devour Your Soul
@diomed
Mar 28 2018 13:21
I'm like, typing it into a search and book shows without word I typed
hehe
to what do I add display:inline?
Diego Mayer
@Chrono79
Mar 28 2018 13:26
@diomed change the width of the name column to 50% and reduce the others so you don't exceed 100%
Year and ... could be narrower
Diego Mayer
@Chrono79
Mar 28 2018 13:31
It seems moving the span with the gliph inside the other span works
May Kittens Devour Your Soul
@diomed
Mar 28 2018 13:33
@Chrono79 hmmm. . . when I change width, that blue text above doesn't shift and it's kinda confusing
truth be told, I don't really need that last set of ... icons at all
how to shift Writer a bit to the right?
Diego Mayer
@Chrono79
Mar 28 2018 13:39
some styles are inline in the html
Diego Mayer
@Chrono79
Mar 28 2018 13:46
<span class="grid-title"><span class="grid-icon m" ng-class="item.icon"></span><a href="#">{{ item.name }}</a></span>
abraham anak agung
@padunk
Mar 28 2018 14:02

Can someone help me explain how this for works?

function listToArray(list) {
  let array = [];
  for (let node = list; node; node = node.rest) {
    array.push(node.value);
  }
  return array;
}

list is an object like {value: 10, rest: {value: 20, rest: null}}

Abdullah
@AbdullahChaudhry
Mar 28 2018 14:11

@padunk It's a loop. For example:
for (let i = 0; i < 10; i++) { console.log('i:', i) }
We start at 0, we stop when i is less than 10, and each time we increment i by 1.

https://repl.it/repls/MediumpurpleGreatAutotote

In above example, it will execute whatever is within the curly brackets (the block)
Then it will increment i by 1, so i becomes 1 on the second iteration
Donnie
@Donnie-D
Mar 28 2018 14:13
Hi fellas! If you look at the pen below. Its all over the place lol. I have created an array of a few links and assigned those links to some variables i.e. rain, cloud, sun etc. Now i want to change the background of my page according to the data pulled from the api. THE PROBLEM is that when i try to compare the words using regexp, i think the comparison is being done against the links the array elements point towards and not the elements themsleves. How could I avoid this situation?
https://codepen.io/Donnie-D/pen/YaydRM?editors=0010
abraham anak agung
@padunk
Mar 28 2018 14:13
@AbdullahChaudhry yes i know how for loops work, but in that code above, how does it work?
Abdullah
@AbdullahChaudhry
Mar 28 2018 14:13
then it checks, is i less than 10 ? If true then it will repeat the same thing, execute the block, increment i by 1 and then check again. If i isn't less than 10 then it will break out of the loop
@padunk What kind of list is the function going to take. Is there an example?
abraham anak agung
@padunk
Mar 28 2018 14:16
@AbdullahChaudhry function listToArray take an object like {value: 10, rest: {value: 20, rest: null}} as an input and the output is [10, 20] so it just change an object to an array.
Donnie
@Donnie-D
Mar 28 2018 14:23
@AbdullahChaudhry hey
Michael Grienauer
@mgrienauer
Mar 28 2018 14:30
//create function that take a streamer username as input and returns json data from twitch api
  function ajaxStreamCall(streamer){
    //make ajax call with streamer name to check stream status
    $.ajax({
     type: 'GET',
     url: 'https://api.twitch.tv/kraken/streams/' + streamer,
     headers: {
       'Client-ID': 'ieym1jzi0ljgp9ntvvw0dcuxaw4hzf'
     },
     // log data to console if success
     success: function(data) {
       console.log(data);
       //create function that takes twitch api data and updates html on page
       function updateStreamData(){
         //update html on streamer div to display current stream info
         if (data.stream !== null){
          $('#' + streamer).append('<p>online</p>');
         }
       }
     }
    });
  }
so im trying to target a div with an id that is equal to the arg, streamer
how can i do this in jquery
$('#' + streamer).append('<p>online</p>');
this is the line im talking about but i dont think it's correct
abraham anak agung
@padunk
Mar 28 2018 14:32
$("#streamer")
Michael Grienauer
@mgrienauer
Mar 28 2018 14:34
@padunk i tried that but it doesnt work
Abdullah
@AbdullahChaudhry
Mar 28 2018 14:35

@padunk Okay, the loop begins by assigning list to the node variable.
It then pushes node.value into the array, then assigns node.rest to node (which is a reference to the next object).

It then checks node, this will pass as true if truthy, but will be false if falsy value.

The loop stops when node.rest is null.

Michael Grienauer
@mgrienauer
Mar 28 2018 14:36
nevermind, my syntax was right but i forgot to call the function after haha
duh
Abdullah
@AbdullahChaudhry
Mar 28 2018 14:39
let num = 10

for (let i = 0; num; i++) {
  console.log('i:', i)
  num--
}

Check this loop above. On each iteration it will check num, num will be true all the way until it reaches zero (will become falsy)

Recall that:

if (1) { console.log('true') } // true
if (0) { console.log('true') } // false (does not console.log true)
abraham anak agung
@padunk
Mar 28 2018 14:39
@AbdullahChaudhry let me digest this first.
Abdullah
@AbdullahChaudhry
Mar 28 2018 14:55
abraham anak agung
@padunk
Mar 28 2018 14:57
@AbdullahChaudhry Thank you for the explanation :+1:
CamperBot
@camperbot
Mar 28 2018 14:57
padunk sends brownie points to @abdullahchaudhry :sparkles: :thumbsup: :sparkles:
:cookie: 311 | @abdullahchaudhry |http://www.freecodecamp.org/abdullahchaudhry
Daniel Romero
@Ranacode
Mar 28 2018 15:19
@IsaakNazar I can give you a hint, you need to use a double ternary expression to achieve all the conditions that render the three buttons
Nazar
@IsaakNazar
Mar 28 2018 15:20
@Ranacode thx, I've completed this challenge
Daniel Romero
@Ranacode
Mar 28 2018 15:20
ok :)
Jason Luboff
@JLuboff
Mar 28 2018 16:20
:fire:
Nate Mallison
@NJM8
Mar 28 2018 18:15
Does anyone here use cloudflare? Or can point me to a decent explanation of A records and CNAME's and ip addresses. I have a general understanding but don't really get how things are hooked up in my particular situation. The problem is my website only loads if you include the www
Jason Luboff
@JLuboff
Mar 28 2018 18:17
I don't use cloudflare, but can give a little bit of info on the DNS questions. A records (or Host record) maps an IP address to a host name. I.e www.google.com maps to 74.125.196.105. A CNAME (canonical name) record, is just an alias. So I could have www.myCoolWebsiteIsActuallyGoogle.com which would point to www.google.com A record
Nate Mallison
@NJM8
Mar 28 2018 18:22
so, my CNAME file has www.natethedev.com in it, but my A record is natethedev.com -> ip address
Christopher McCormack
@cmccormack
Mar 28 2018 18:22
What is the full cname
Nate Mallison
@NJM8
Mar 28 2018 18:23
and I have a CNAME record in cloudflare that points www -> njm8.github.io.
so maybe my CNAME file on my website should be natethedev.com, and then it will work?
Jason Luboff
@JLuboff
Mar 28 2018 18:25
I'll let @cmccormack handle it from here, I haven't worked with CNAME's enough to answer
Christopher McCormack
@cmccormack
Mar 28 2018 18:25
www.natethedev.com.        CNAME  natethedev.com.
natethedev.com             A  [your ip].
Nate Mallison
@NJM8
Mar 28 2018 18:25
@cmccormack That's where I get confused, I have a CNAME file actually on my host that was generated by github when I hooked up the custom domain. but there are CNAME records on my cloudflare DNS page. What's the difference between the actual file and the record on cloudflare
Christopher McCormack
@cmccormack
Mar 28 2018 18:26
@JLuboff hah no you're good man I'm not 100% familiar with CNAMES either
Jason Luboff
@JLuboff
Mar 28 2018 18:26
@cmccormack Probably a bit more than me ;)
Nate Mallison
@NJM8
Mar 28 2018 18:26
And for that layout, which makes sense to me, what should be in the CNAME file
Christopher McCormack
@cmccormack
Mar 28 2018 18:26
@NJM8 who is hosting natethedev.com?
Nate Mallison
@NJM8
Mar 28 2018 18:26
hosing! I hope no one
haha
Christopher McCormack
@cmccormack
Mar 28 2018 18:26
hah
Nate Mallison
@NJM8
Mar 28 2018 18:26
github
Christopher McCormack
@cmccormack
Mar 28 2018 18:27
hmm you purchased that domain through github?
Nate Mallison
@NJM8
Mar 28 2018 18:27
github pages, namecheap for domain name, cloudflare for CDN and caching magics
Jason Luboff
@JLuboff
Mar 28 2018 18:28
So namecheap handles your domain and dns then?
Nate Mallison
@NJM8
Mar 28 2018 18:28
I feel like my cname file should have natethedev.com in it since that is what the a record is on cloudflare
I think so?
Jason Luboff
@JLuboff
Mar 28 2018 18:29
Well where are you changing your DNS records?
Nate Mallison
@NJM8
Mar 28 2018 18:29
TBH it seems like there are about 500 different ways to configure this stuff
oh, no, cloudflare took over since they need to point things to their servers. namecheap just points to their servers now
I think namecheap took care of the natethedev.com -> www.natethedev.com hook up in the background which cloudflare is not doing
but I have it without WWW in my A record pointing to some IP address, then www. pointing to the github address of my page
now nothing loads, that wasn't the answer, haha
Jason Luboff
@JLuboff
Mar 28 2018 18:34
Keep in mind that DNS records can take upwards of 48 hours to propagate the internet. Generally... they are quick but sometimes can be very slow
Nate Mallison
@NJM8
Mar 28 2018 18:36
yeah, that's why I want to know before making changes, I don't have 8 days to test 4 changes.
I will say namecheaps support is way better than cloudflares
Christopher McCormack
@cmccormack
Mar 28 2018 18:36
└─► # dig @8.8.8.8 +trace www.natethedev.com

; <<>> DiG 9.10.3-P4-Ubuntu <<>> @8.8.8.8 +trace www.natethedev.com
; (1 server found)
;; global options: +cmd
.                       43389   IN      NS      i.root-servers.net.
[...]
;; Received 525 bytes from 8.8.8.8#53(8.8.8.8) in 31 ms

com.                    172800  IN      NS      g.gtld-servers.net.
[...]
;; Received 1178 bytes from 199.7.91.13#53(d.root-servers.net) in 57 ms

natethedev.com.         172800  IN      NS      austin.ns.cloudflare.com.
natethedev.com.         172800  IN      NS      liv.ns.cloudflare.com.
[...]
;; Received 673 bytes from 192.52.178.30#53(k.gtld-servers.net) in 39 ms

www.natethedev.com.     300     IN      A       104.31.91.98
www.natethedev.com.     300     IN      A       104.31.90.98


└─► # dig @8.8.8.8 +trace natethedev.com

; <<>> DiG 9.10.3-P4-Ubuntu <<>> @8.8.8.8 +trace natethedev.com
; (1 server found)
;; global options: +cmd
.                       144367  IN      NS      a.root-servers.net.
[...]
;; Received 525 bytes from 8.8.8.8#53(8.8.8.8) in 33 ms

com.                    172800  IN      NS      h.gtld-servers.net.
[...]
;; Received 1174 bytes from 192.36.148.17#53(i.root-servers.net) in 134 ms

natethedev.com.         172800  IN      NS      austin.ns.cloudflare.com.
natethedev.com.         172800  IN      NS      liv.ns.cloudflare.com.
[...]
;; Received 669 bytes from 192.26.92.30#53(c.gtld-servers.net) in 109 ms

natethedev.com.         300     IN      A       104.31.90.98
natethedev.com.         300     IN      A       104.31.91.98
;; Received 75 bytes from 173.245.59.70#53(austin.ns.cloudflare.com) in 15 ms
looks like you're getting the same results from cloudflare
Nate Mallison
@NJM8
Mar 28 2018 18:38
so the problem isn't on cloudflares end, right?
Christopher McCormack
@cmccormack
Mar 28 2018 18:40
neither seems to be loading for me
is your host enabled?
Nate Mallison
@NJM8
Mar 28 2018 18:42
I just screwed around with the CNAME a bit, try it again
ah no, I did a dumb thing
I changed the IP address the A record pointed to and I didn't write the old one down
der der der
is one of those ip address up there the one I should be using?
Christopher McCormack
@cmccormack
Mar 28 2018 18:48
Those are what cloudflare is resolving
Nate Mallison
@NJM8
Mar 28 2018 18:48
so not the host IP address which is probably what I want right?
Christopher McCormack
@cmccormack
Mar 28 2018 18:49
if you follow the trail, the top level . resolves com, then com has two NS records for natethedev.com that resolve to cloudflare. cloudflare then has the A records for both www.natethedev.com and natethedev.com
It's all hierarchical so natethedev.com will always be resolved before www.natethedev.com
ignoring exceptional cases of course
Nate Mallison
@NJM8
Mar 28 2018 18:53
I see, so it sounds like all that is ok, except that I just changed the IP address it points to and they don't have a back button
sweet
Christopher McCormack
@cmccormack
Mar 28 2018 18:54
when in doubt use dig!
Nate Mallison
@NJM8
Mar 28 2018 18:55
right, so if I dig njm8.github.io github tells me I will get the full resolution path
NATHAN-J-MALLISONs-MacBook-Pro:njm8.github.io natemallison$ dig njm8.github.io

; <<>> DiG 9.9.7-P3 <<>> njm8.github.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33458
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 8192
;; QUESTION SECTION:
;njm8.github.io.            IN    A

;; ANSWER SECTION:
njm8.github.io.        3600    IN    CNAME    sni.github.map.fastly.net.
sni.github.map.fastly.net. 25    IN    A    151.101.185.147

;; Query time: 69 msec
;; SERVER: 209.18.47.61#53(209.18.47.61)
;; WHEN: Wed Mar 28 14:54:17 EDT 2018
;; MSG SIZE  rcvd: 98
so should it point to 208.18.47.61 or 151.101.185.147?
Christopher McCormack
@cmccormack
Mar 28 2018 18:56
Sorry what are you pointing at an IP for?
Jason Luboff
@JLuboff
Mar 28 2018 18:56
For the A record I'd assume
Christopher McCormack
@cmccormack
Mar 28 2018 18:57
why can't github point to the dns name?
Nate Mallison
@NJM8
Mar 28 2018 18:57
well, since the 208 is what is already in there cause I pasted it in without thinking and not working, I'm going to use my divination powers to say I should try the 151
Christopher McCormack
@cmccormack
Mar 28 2018 18:58
Where are you doing this? What are you pointing to what?
You should almost never be pointing to a static address if you can avoid it
Nate Mallison
@NJM8
Mar 28 2018 18:58
Original issue is that natethedev.com serves a 522 timeout error after 30 seconds, where www.natethedev.com serves the site
in trying different things I changed the IP address for the A record but IDK what it was in the first place
so now I'm trying to get the correct IP address for the A record, then I think I need to have github whitelist the the ip address list from cloudflare for all their servers
Jason Luboff
@JLuboff
Mar 28 2018 19:00
Who originally created the A record?
Christopher McCormack
@cmccormack
Mar 28 2018 19:01
so are you saying cloudflare is serving the wrong A record?
Nate Mallison
@NJM8
Mar 28 2018 19:03
Well, I'm not sure why natethedev.com wasn't serving, but when you just loaded it yes, wrong ip address for the A record (that I put in). I just changed it to the address in the DIG above and now both sites are serving. But you say I shouldn't be pointing there, but instead to one of githubs CDN servers I assume?
@JLuboff Magic. namecheap populates it for you and cloudflare did the same when I sign up and added my domain
Jason Luboff
@JLuboff
Mar 28 2018 19:05
Have you tried contacting namecheap?
Christopher McCormack
@cmccormack
Mar 28 2018 19:05
is njm8.github.io your github page?
ah I see it is
ok thought it was a cdn for github
Nate Mallison
@NJM8
Mar 28 2018 19:06
Well either way things are working now and I think I will contact github to make sure I am using the correct IP address and see about whitelisting all of cloudflares servers
Christopher McCormack
@cmccormack
Mar 28 2018 19:06
So when you say you changed it to the IP above was this on cloudflare?
Nate Mallison
@NJM8
Mar 28 2018 19:06
I did not contact namecheap yet, their chat support is amazing but last time they said cloudflare handles the dns now
@cmccormack yes
Christopher McCormack
@cmccormack
Mar 28 2018 19:07
ok - can you add the host instead of ip - njm8.github.io?
this way if github is using load balancing or anything you don't break
Jason Luboff
@JLuboff
Mar 28 2018 19:08
Shouldn't load balancing point to the same IP though?
Christopher McCormack
@cmccormack
Mar 28 2018 19:08
it's only resolving a single IP currently but serving multiple IPs is just one way of providing redundancy. They could also be using GTM which does a lookup based on some criteria and serves a single record based on that instead
I don't mean traffic load balancer like an F5 VIP in front of a server cluster, I mean DNS load balancing
Jason Luboff
@JLuboff
Mar 28 2018 19:09
Ah
Nate Mallison
@NJM8
Mar 28 2018 19:09
has to be an ipv4 address
Christopher McCormack
@cmccormack
Mar 28 2018 19:12
@NJM8 I think you're missing some steps to actually make this work properly with github pages
Did you read through this? https://help.github.com/articles/setting-up-an-apex-domain/
from a cursory glance you would configure your custom domain on github pages then point your DNS service toward the github nameservers 192.30.252.153/192.30.252.154
Which makes a lot more sense to me as github should have the ability to change IPs whenever they want
that's why we have DNS in the first place
huh, apparently I have configured this myself @ cmccormack.github.io - let me see how I did it
Nate Mallison
@NJM8
Mar 28 2018 19:28
Thanks @cmccormack I'll read through that again. I went through a lot of it at first but then namecheap did some magic to make natethedev.com work and I moved on
CamperBot
@camperbot
Mar 28 2018 19:28
njm8 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1383 | @cmccormack |http://www.freecodecamp.org/cmccormack
Christopher McCormack
@cmccormack
Mar 28 2018 19:29
@NJM8 good luck
Nate Mallison
@NJM8
Mar 28 2018 19:29
I'll note that in here they say it should point to the output of dig, https://help.github.com/articles/troubleshooting-custom-domains/
Nate Mallison
@NJM8
Mar 28 2018 19:34
@cmccormack @JLuboff While you guys are here do you want to test out my JS calculator? :smile: :smile: I think I found all the input bugs
Christopher McCormack
@cmccormack
Mar 28 2018 19:34
@NJM8 yeah you may be right - those don't appear to be name servers. I still recommend checking to see if you can do a CNAME or ANAME record on your DNS host to your github.io url, as you can see in the examples below what you were pointing out to me
@NJM8 I'll take a look after lunch sorry
Tiago Correia
@tiagocorreiaalmeida
Mar 28 2018 19:36
Nate Mallison
@NJM8
Mar 28 2018 19:43
no, having a problem?
Tiago Correia
@tiagocorreiaalmeida
Mar 28 2018 19:52
some animations are really slow I have no idea why :\
and bit slow I mean really slow
even tough on their platform it looks great
Christopher McCormack
@cmccormack
Mar 28 2018 20:22
you try it in a codepen @tiagocorreiaalmeida ?
Jason Luboff
@JLuboff
Mar 28 2018 20:27
@NJM8 Testing it out now. Couple of items.
  1. Super long numbers run off the screen
  2. It seems that if I make a number negative first (using the +- button), then = doesn't work?
  3. I can select an operator, and then use the +- button and it'll keep adding - and I can add another operator, etc.
    Otherwise, works well!
Tiago Correia
@tiagocorreiaalmeida
Mar 28 2018 20:34
somehow its allready looking good and sometimes gets slow again its a strange situation :D
io.on("connection", (socket) => {
    socket.on("REGISTER", async (data) => {
        let { email, username, password } = data;

        try {
            let emailInUse = await User.findOne({ email });
            if (emailInUse) return;//send info message;

            let usernameInUse = await User.findOne({ username });
            if (usernameInUse) return; //send info message;
        } catch (e) {
            //send error message
        }

    })
})
Im looking at this just getting started and would it make sense to have a single emiter for errors or every request if there's an error send it as an object proprety and check for it on the client side?
Christopher McCormack
@cmccormack
Mar 28 2018 20:39
@tiagocorreiaalmeida is that socket.io?
I'm not using that, but that's how I send error to my frontend, with a JSON object
Tiago Correia
@tiagocorreiaalmeida
Mar 28 2018 20:40
yeah im building a chat still I need to handle user register first, yeah I guess im going that way thanks tough
Jason Luboff
@JLuboff
Mar 28 2018 20:46
Ah... socket.io.. super cool and super annoying
Tiago Correia
@tiagocorreiaalmeida
Mar 28 2018 20:46
ahahah @JLuboff :D last weekend had finally my hands on mocha and chai, andrew mead would be proud
Jason Luboff
@JLuboff
Mar 28 2018 20:47
@tiagocorreiaalmeida Oh ya? I still need to figure out how to use it for my app. I should actually probably go back to his course and finish it too lol
Tiago Correia
@tiagocorreiaalmeida
Mar 28 2018 20:48
I atually based my self on his idea the todo one cause I was out of ideas, made a really simple one but was good in a overall
I took his react one aswell two months ago, the main never fails
Jason Luboff
@JLuboff
Mar 28 2018 20:49
React one as good?
Tiago Correia
@tiagocorreiaalmeida
Mar 28 2018 20:50
yeah pretty good I jumped out at 70% because he started to use firebase and I wasnt that interested in it, but I was able to build a few stuff after based on what I learned
Jason Luboff
@JLuboff
Mar 28 2018 20:51
Nice, ya I think I got through about 70% of the node course before jumping ship lol
Still need to go through the async portion, I think that'd be good to know
Tiago Correia
@tiagocorreiaalmeida
Mar 28 2018 20:56
I somehow learned it myself but he also does a good job explaning it
Jason Luboff
@JLuboff
Mar 28 2018 20:57
I've just stuck with callbacks/promises which work but find myself getting somewhat lost with promises (although @alpox definitely helped me with that!)
Tiago Correia
@tiagocorreiaalmeida
Mar 28 2018 21:05
well something funny is that was also alpox who got me into async await :D
Jason Luboff
@JLuboff
Mar 28 2018 21:06
:D He's a smart fella
Tiago Correia
@tiagocorreiaalmeida
Mar 28 2018 21:18
what would be the best way to listen for event emitters from socketio on react components side? since I can't write directly socket.on , on the component
Jason Luboff
@JLuboff
Mar 28 2018 21:21
No clue
Dardan Demiri
@dardandmr
Mar 28 2018 21:37
Wow this is strange
function updateRecords(id, prop, value) {
  if(collection[id]){
    if(collection[id][prop]){
      collection[id][prop].push(value);
      return collection;
    }else{
        collection[id].prop = value;
        console.log(prop);
        return collection;
    }
  }
}

When testing it:

updateRecords(5439, "tracks", "Take a Chance on Me");
logs  > ( tracks )

but the property name is

5439:
     album: "ABBA Gold"
     prop: "Take a Chance on Me"

Why is it not tracks ?
Any idea ?

Brad
@bradtaniguchi
Mar 28 2018 21:39
@tiagocorreiaalmeida Well are you using Redux (idk much about it, but Id think hooking it up to that makes sense in my brain)
@dardandmr I feel like were missing what the data looks like initially
Tiago Correia
@tiagocorreiaalmeida
Mar 28 2018 21:40
instead of taking care of it on react components move it to redux and handle the events directly there? yeah makes sense indeed
Dardan Demiri
@dardandmr
Mar 28 2018 21:41
the data is this as written above
5439:
     album: "ABBA Gold"
     prop: "Take a Chance on Me"
This is the important part
why is the name prop and not tracks
when you try it like this:
updateRecords(5439, "tracks", "Take a Chance on Me");
Brad
@bradtaniguchi
Mar 28 2018 21:42
Ah I see
This line: collection[id].prop = value;
Dardan Demiri
@dardandmr
Mar 28 2018 21:42
yes
Brad
@bradtaniguchi
Mar 28 2018 21:42
Always assigns to 'prop', you need to use the braket notation to dynamically assign it to prop
collection[id][prop] = value;
Since prop is a variable, unless you use bracket notation JS thinks you want to assign it to the word prop (not what the variable represents)
Dardan Demiri
@dardandmr
Mar 28 2018 21:43
Uncaught TypeError: collection[id][prop].push is not a function
Brad
@bradtaniguchi
Mar 28 2018 21:43
prop isn't array , thus you can't use push
Dardan Demiri
@dardandmr
Mar 28 2018 21:44
yes but why is it entering the If
since the prop isn't there
function updateRecords(id, prop, value) {
  if(collection[id]){
    if(collection[id][prop]){
      collection[id][prop].push(value);
      return collection;
    }else{
        collection[id].prop = value;
        console.log(prop);
        return collection;
    }
  }
}
Jason Luboff
@JLuboff
Mar 28 2018 21:45
prop does exist
Dardan Demiri
@dardandmr
Mar 28 2018 21:45
"5439": {
      "album": "ABBA Gold"
    }
it's just album
or is the if ( if ANY PROP )
?
really strange
Brad
@bradtaniguchi
Mar 28 2018 21:46
if ('sometext') console.log('this will print');
Dardan Demiri
@dardandmr
Mar 28 2018 21:46
yeah
Brad
@bradtaniguchi
Mar 28 2018 21:47
You need to check to see if the dynamic prop is an array, then push. Since a string AND array are both truthy you can't just check if it exists and assumes you can push
well a non-empty string that is
Dardan Demiri
@dardandmr
Mar 28 2018 21:47
function updateRecords(id, prop, value) {
  if(collection[id]){
    if(collection[id][prop] !== ""){
      collection[id][prop] = value;
      return collection;
    }else{
        collection[id][prop] = value;
        console.log(prop);
        return collection;
    }
  }
}
now it's working
@bradtaniguchi thanks bro
CamperBot
@camperbot
Mar 28 2018 21:48
dardandmr sends brownie points to @bradtaniguchi :sparkles: :thumbsup: :sparkles:
:cookie: 437 | @bradtaniguchi |http://www.freecodecamp.org/bradtaniguchi
Brad
@bradtaniguchi
Mar 28 2018 21:48
@dardandmr np :D
Jason Luboff
@JLuboff
Mar 28 2018 22:47
Anyone have experience using cron jobs in node?
Stephen James
@sjames1958gm
Mar 28 2018 22:55
@JLuboff You mean cron jobs that run node tasks?
Jason Luboff
@JLuboff
Mar 28 2018 22:57
@sjames1958gm Mmm... cron jobs within a node app that will fire off a function every XX time period such as https://www.npmjs.com/package/cron
Stephen James
@sjames1958gm
Mar 28 2018 22:58
@JLuboff So your node application is always running?
Jason Luboff
@JLuboff
Mar 28 2018 22:58
Essentially I need a job to check daily.. if a task hasn't been updated longer than 7 days, at which point it will send an email to the individual telling them to get their ass back to work :joy:
Yes it will be
Negating any downtime due to server/power/etc
Stephen James
@sjames1958gm
Mar 28 2018 23:02
What issues are you having?
Jason Luboff
@JLuboff
Mar 28 2018 23:03
I was more so going to get an opinion on which package is best suited I guess. I think this one will do (and it seems to be used the most) but I just don't have any experience with it. I'm going to need to fire off 1 or more SQL queries within it so just want to make sure I'm not doing something odd lol
Stephen James
@sjames1958gm
Mar 28 2018 23:05
@JLuboff Yeah, I guess you could just start a settimeout yourself with a minimum cycle time and check the date each time to decide to fire off the event.
Jason Luboff
@JLuboff
Mar 28 2018 23:05
Any reason that would be better or worse over using cron?
Stephen James
@sjames1958gm
Mar 28 2018 23:06
@JLuboff I can't see anything significant
Jason Luboff
@JLuboff
Mar 28 2018 23:06
@sjames1958gm Ok thanks :D
CamperBot
@camperbot
Mar 28 2018 23:06
jluboff sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9143 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Dardan Demiri
@dardandmr
Mar 28 2018 23:14
@sjames1958gm
Stephen James
@sjames1958gm
Mar 28 2018 23:15
@dardandmr :wave:
Dardan Demiri
@dardandmr
Mar 28 2018 23:15
What's this bro
blob
:P
Stephen James
@sjames1958gm
Mar 28 2018 23:15
@dardandmr That is test number 11 :)
Dardan Demiri
@dardandmr
Mar 28 2018 23:15
Oh great that clear now :P
hahahhaha
Stephen James
@sjames1958gm
Mar 28 2018 23:15
@dardandmr I get distracted easily, it was something I was going to play with and forgot about :)
Dardan Demiri
@dardandmr
Mar 28 2018 23:17
Same problem here
Jason Luboff
@JLuboff
Mar 28 2018 23:17
Got a test cron job working..but seems like my 30 second interval is taking a lot longer...that...or I'm inpatient :joy:
Yup.. taking a minute but thats not a big deal
Stephen James
@sjames1958gm
Mar 28 2018 23:20
@JLuboff Hmm, that is odd. Do you have some intensive tasks running?
Dardan Demiri
@dardandmr
Mar 28 2018 23:20
@sjames1958gm You know a lot about programming, and I thought
I must look at his website, it must be something special...
Then that happened :P :clap:
Jason Luboff
@JLuboff
Mar 28 2018 23:20
@sjames1958gm No, no processing was occuring at the time, just the app running. I have a feeling my cron string isn't right
Nate Mallison
@NJM8
Mar 28 2018 23:20
Thanks for looking @JLuboff . I'm going to have to re write the logic that appends the input to the display. Thats where all the trouble is. It's already like 50 lines with 9-10 if statements to check for different states. I was thinking to make a mini state machine out of it.
CamperBot
@camperbot
Mar 28 2018 23:20
njm8 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2383 | @jluboff |http://www.freecodecamp.org/jluboff
Stephen James
@sjames1958gm
Mar 28 2018 23:21
@dardandmr Most of my programming is not user facing.
Nate Mallison
@NJM8
Mar 28 2018 23:21
The truth comes out!
😂😂
Dardan Demiri
@dardandmr
Mar 28 2018 23:22
@sjames1958gm great
Jason Luboff
@JLuboff
Mar 28 2018 23:23
@NJM8 Whats a few more if statements than? ;)
FlashHero
@FlashHero
Mar 28 2018 23:26
@JLuboff I tried nodemailer and it worked to send the email but it uses the authorized email for the from property and it even says in the documentation but do you know any solutions for this because it sends the email to itself (the authorized email) which is mine
Jason Luboff
@JLuboff
Mar 28 2018 23:29

@FlashHero You should be able to set the from property to whatever you like

(from, to, subject) => {
  let transporter = nodeMailer.createTransport(mailConfig),
      message = {
        from,
        to,
        subject
      };
......
}

In the above I'm using a function to set the properties, and can pass in an email (say from a form) to the function (my syntax isn't all there but oyu get the idea)

OOORRR set it to a fixed email

  let transporter = nodeMailer.createTransport(mailConfig),
      message = {
        from: 'FlashHero@flashhero.com',
        to,
        subject
      };
FlashHero
@FlashHero
Mar 28 2018 23:32
@JLuboff This is what nodemailer documentation says Gmail also always sets authenticated username as the From: email address. So if you authenticate as foo@example.com and set bar@example.com as the from: address, then Gmail reverts this and replaces the sender with the authenticated user. I did that but it doesn't work it overrides with the authenticated account email
Jason Luboff
@JLuboff
Mar 28 2018 23:33
Ah.. gotcha. I'm not using Gmail, I'm using an internal SMTP server
I remember reading in the docs that Gmail is a bit problematic in the first place too. Sometimes it just wont work
FlashHero
@FlashHero
Mar 28 2018 23:35
@JLuboff even outlook seems to have problems it would only work if you send emails with the authenticated email or else it gives you errors
Jason Luboff
@JLuboff
Mar 28 2018 23:46
@FlashHero Hmmm not sure how to get around that. I would probably just go the route of putting the users email in the body or subject of the email
FlashHero
@FlashHero
Mar 28 2018 23:47
@JLuboff ok I'll look into it thanks
CamperBot
@camperbot
Mar 28 2018 23:47
flashhero sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2384 | @jluboff |http://www.freecodecamp.org/jluboff
Mel Macaluso
@MelMacaluso
Mar 28 2018 23:47
Hello, I have a web app based on vuejs / vuetify /webpack and I am doing some get/post from thirdparty apis with axios, that requires sending in the header the api key, which obviously is bad practice. What would be the steps to instead send the user form data to the server (ie. Express) then the server handles it and then posts back to the frontend the json? (so that the api header request is never seen by the frontend and thus exploited).
Jason Luboff
@JLuboff
Mar 28 2018 23:50
@MelMacaluso There is potentially an npm package for the API which you could use, or use node's https module to make a call to the api and then serve the data to the frontend
Mel Macaluso
@MelMacaluso
Mar 28 2018 23:50
Hi @JLuboff thanks for taking your time into answering
CamperBot
@camperbot
Mar 28 2018 23:50
melmacaluso sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2385 | @jluboff |http://www.freecodecamp.org/jluboff
Mel Macaluso
@MelMacaluso
Mar 28 2018 23:51
"There is potentially an npm package for the API which you could use" are we talking about sending to express?
Jason Luboff
@JLuboff
Mar 28 2018 23:51
you would run the package within an express app, yes
Mel Macaluso
@MelMacaluso
Mar 28 2018 23:53
sorry about the lack of knowledge but if I used node's https module to make a call to the api I am still having the same problem I currently have with axios:
FlashHero
@FlashHero
Mar 28 2018 23:53
@MelMacaluso send the user form data to the server for this you can use npm package called bodyParser which lets you get the form data using req.body.formName and then you can do whatever you want with the data
Jason Luboff
@JLuboff
Mar 28 2018 23:53
The user doesn't see anything on the backend and you can hide the API key in an enviornment variable
Axios can be used within node/express as well
Mel Macaluso
@MelMacaluso
Mar 28 2018 23:57
understood thanks for that guys
What would be the steps to boot express into my current app?
as in top level steps