« first day (4073 days earlier)      last day (882 days later) » 

6:07 AM
Good evening, gentlemen. I'm learning Node and made my first test server and request today.
I've been able to start the server and send the request, but it's not doing what I'm trying to do (delete a file).
Would anyone be willing to take a quick look to spot my newbie mistake?
It's not much code

https://gist.github.com/PurpleMongrel/bca75be68b9617ffe1b741663c12f909
 
@PurpleMongrel Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
7:03 AM
Hi @PurpleMongrel, There are a a bunch of good concepts in there but a lot of problems too. I'd suggest starting with something a little simpler and build up to the webserver deleting files.
The biggest mistake I see here (aside from the fact that it doesn't run) is that you're trying to delete whatever path is passed in as the request url. Never let users submit unsanitized data to be used like that. Suppose someone submitted a request at yourserver:8000/windows?
Would it trash your C:\windows folder? Maybe. Another problem is that it doesn't know where to find urlPath and stat functions. This is why I think you have to start smaller. Write the smallest thing possible & run it. Then add something else & run it again... by the 100th time you run it, you should have something that runs and does something useful. If you can write the 'file delete' part of your app as a script you run from the command-line, you can sidestep the webserver aspect for now.
 
@4umfreak hey thanks for the answer, The server creation code is from eloquent javascript - the book ive been following. i wrote the test-request - just trying to do something with the server code from the book.
@4umfreak Why does it not know how to find the urlPath and stat functions? Isnt urlPath defined in same file that the DELETE method is in? Sorry I know this is newbie to the max but its where im at. I have been able to do things more simply with curl, but i was hoping ot understand how i can do something with the authors code (create-server.js in the gist)
@4umfreak create-server.js also has const {stat, readdir} = require("fs").promises; -> this doesn't do it?
@4umfreak Sorry for extreme newbiness. Been spending honourable amounts of time suffering - just coming to chat to try to expedite learning a bit
 
The stat function live in the fs package. You would have to require it like: const fs = require("fs"); the use it like const stats = await fs.stat(path);
I don't know where the urlPath function is from...
 
7:18 AM
urlPath function is in create-server.js in the gist i posted (i did update it a while back though so maybe you saw before i added the rest of code?)
create-server.js also has the line const {stat, readdir} = require("fs").promises;
 
Yeah there's no require fs in the one I saw..
 
@4umfreak do you see it now? I made a mistake and hadnt pasted all code before. sorry about that
 
Note that the require statements are typically placed at the top of the file. I'd seen an early version without them.
 
@4umfreak good to know. I guess the authors "educational" code is often somewhat unrealistic. Thanks for mentioning though. Makes sense that requires would be on top
 
While you're writing code like this, sprinkle console.log() statements around liberally so you can follow that code execution path as it runs. If you have VSCode, you can step through it and inspect variables to see what they contain..
I've never created a server like this, only with Express and Restify so the code structure feels weird to me. If you follow what's going on here on day #1 with Node, I'd say you're doing well!
 
7:46 AM
@4umfreak I appreciate the encouragement!
 
 
5 hours later…
12:42 PM
Hi All
im facing one issue, with Facebook & Instagram token revoking
when I connect with FB and instagram, I get two different token, Im using the below graph API for token generation
https://graph.facebook.com/v6.0/oauth/access_token?grant_type=fb_exchange_token&client_id=MY_FB_APP_ID&client_secret=MY_FB_APP_SECRET&fb_exchange_token=TOKEN_GENERATED_FROM_PREVIOUS_API
but when Im revoking the token with the below graph api
https://graph.facebook.com/v6.0//${facebookUserId}/permissions?access_token=${accessToken}
even though I revoke the token only for the facebook account even though my Instagram account token is getting expired.
 
1:00 PM
Hello, any mate here?
 
@SahidulIslam Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
Hello, I am learning js. However, I can't solve problem effectively even I know js.

How can I be a good problem solver related to web
 
 
1 hour later…
2:03 PM
@SahidulIslam Just keep doing :) practice makes a man perfect. It is common for almost all kind of beginners or learners, you will be better and better with the passage of time and more and more practice.
 
@sheerazabbas Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
2:35 PM
Hello, just a quick question: How can I call a JSON object in the javascript lambda code
 
@Zani123 Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
what function to use for that
 
3:25 PM
My server is using this trick by @ed-ta to prevent Node.js busboy from processing file uploads that get too big: https://stackoverflow.com/questions/39681966/avoiding-further-processing-on-busyboy-file-upload-size-limit . The server is doing its job and cancelling as soon as the file upload exceeds the allowable size; unfortunately, my XMLHttpRequest on the client isn't firing the onerror or onabort events until **after** the client has processed the entire file.

How do I get the client to respond to the 455 status code in a timely manner?
 
 
2 hours later…
5:36 PM
Is there a way to do something like this in react?

<{link ? 'a' : 'div'>hi</ {link ? 'a' : 'div'}>
to conditionalize the tagname being rendered?
 
yes
if (x) { div } else { anchor }
 
any chance you could show a fiddle?
 
yes I know that's possible, but I need to conditionalize the tag type of a parent element that has lots of children. I'd like to do it all in one component, without having to factor the shared inner content into its own component and have each of the possible parent component tagtypes render that shared child component
 
you can't do it within the tag itself
 
5:39 PM
@duhaime Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
 
james bot you're not helping
 
1 message moved to Trash can
 
but you can have a component that is either div or a based on a given condition, that then has the same children
<divora> children </divora>
 
I just wish I could inline conditionalize the tag type
 
since elements have to be whole, it's not possible
for example, you can't do:
if (foo) { <div> }
some content
if (foo) { </div> }
because <div> implies </div>
the component with children option is the cleanest
since then the children aren't part of the condition
 
6:39 PM
Guys, I wrote 1 answer which I was not very complete. It got downvote. I deleted it and added an improved answer, is it against SO rules?
Ok, deleted both now. Will try to avoid in the future.
Did this because I was already kind of in the process of improving it when it got downvote.
 
7:29 PM
@duhaime you can always do this:
<div>
{(() => {
   if (x){
        return <div>bla</div>
   }
   return <a>bla</a>
})()}
</div>
ugly, maybe, but it works
 
@GiorgiMoniava Ideally, just edit the existing one next time. Deleting something because it's downvoted and then reposting it is bad
that can be seen as trying to circumvent the system, and people with enough rep to see it may downvote the new one simply due to that.
 
@KevinB Yep, will do that. Yeah I did this because I thought people would be biased of thinking badly about the answer because it was downvoted, when in reality I had updated it.
@KevinB Also one more question, sometimes when i answer a question and feel there is little activity in the thread, if the question is not too bad, I have sometimes (rarely though) upvoted the question, to attract more attention to the question - and implicitly with the hope that someone will upvote my answer too, if mine is good answer. Can this also be seen as major cheating?
@KevinB I have some moral issues with my conscience because of it lately so was looking for input from other people :)
 
I disagree with that practice, but you aren't breaking any rules
¯\_(ツ)_/¯
 
@KevinB But that wouldn't highly affect my reputation in the sense that if my answer got upvotes, it still means the answer was good right? So it isn't cheating in that sense
 
correct
see, the way i approach it, is if the question isn't worth me upvoting, why am i answering it?
just because i want rep?
 
7:43 PM
@KevinB I see
yeah maybe sometimes it is balance between getting rep and wanting to help others
@KevinB Ok, thanks for the feedback
 
8:08 PM
@phenomnomnominal do you have a discord?
 
 
2 hours later…
9:58 PM
 

« first day (4073 days earlier)      last day (882 days later) »