« first day (3081 days earlier)      last day (1866 days later) » 
00:00 - 04:0004:00 - 22:00

12:16 AM
Is fine to answer such low quality question or shall I delete my answer?
 
@ToddChaffee Didn't get any answer yet...We're just using standard JS, so no virtual DOM either
 
 
2 hours later…
1:50 AM
@EnderLook people might downvote your answer because of the quality of the question. They look at it as discouraging bad behavior
not saying it's right or wrong, just regurgitating what I was
 
can anyone help me serving image files?
 
@JacobSchneider with node?
 
Yeah
I've got a HTTP server running (no frameworks)
and I've got a working image file
but sending it over HTTP with the correct MIME type and encoding etc, it doesn't seem to work
 
okay, are you using apache, nginx or something else?
 
no just Node HTTP
 
1:58 AM
well, I don't think that will work.
let me pull up the last time I did this
 
The thing is, I've managed to do it before
 
yeah, I was using express.static
115
Q: How to serve an image using nodejs

Nick VanderbiltI have a logo that is residing at the public/images/logo.gif . Here is my nodejs code. http.createServer(function(req, res){ res.writeHead(200, {'Content-Type': 'text/plain' }); res.end('Hello World \n'); }).listen(8080, '127.0.0.1'); It works but when I request for localhost:8080/logo.gif...

 
I'm not using express
 
I know, the link is for one that isn't using express
it's old though
 
Ah sorry
 
2:01 AM
yea, I was just saying that my use case called for express sorry if that was confusing lol
 
haha no worries, I've actually looked at this answer and it hasn't worked
 
scroll down to the one that says "2016 update"
and the example under the heading http
const s = fs.createReadStream(file);
 
With a stream?
 
yeah, that might be the way to do it..
1
Q: How to serve image from Node Server without Express?

ShashankI am working on Node v6.10.2. I am trying to serve static elements with a simple NodeJS program. When I run the below mentioned code and go to http://localhost:3000/, I get this. The image does not get retrieved here. But when I go to http://localhost:3000/img/logo.jpg, I get the image. How do...

 
Not to get off topic, but had a quick question since I'm new here. Do the faded out profile pictures mean the users are idle? And the pictures showing through are active?
 
2:06 AM
@SCodeSK71 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.
 
@JacobSchneider first thing is are you setting the Content-Type?
 
yeah, MIME type is correct
can Firefox render a PNG image if the MIME is image/jpeg?
 
@JacobSchneider can you share your code so I can try it locally?
 
there's a lot
gimme a sec
 
@JacobSchneider you can make a jsbin or gist
@SCodeSK71 I believe so, but I've never asked
 
2:08 AM
Thanks @DavidKamer
 
the more transparent, the longer they've been absent from the chat
 
@DavidKamer thx still learning the chat
 
@DavidKamer I feel like that's not gonna work
here, I'll zip it and send it over
 
@JacobSchneider you can't just make it a gist? I probably won't open a zip tbh
 
Gist, right
 
2:10 AM
I don't need the image files, just the code and I can toss in my own image files to test
or a github repo if it has that much, but probably a good exercise to figure out the relevant part of the code rather than just dumping everything
 
yeah the thing is, the way the backend works is like the express framework, I'm trying to build my own, so a lot of the code is actually necesarry
 
@JacobSchneider hmm, so maybe it's something besides the image serving code causing the problem?
are you using the middleware pattern like express?
 
no, I'm adding a few extra functions to the request and response objects but that's it
http.IncomingMessage.prototype.appendBody = function (text) {
	this.body = this.body || [];
	this.body.push(text);
};

http.ServerResponse.prototype.send = function (body) {
	this.return = this.return || [];
	this.return.push(body);
};
 
oh, I see
 
MutationObserver and AngularJS. I'm seeing that when I get notified of an added form node, it's action (which is hard coded to "{{url}}") has already been resolved by AngularJS. Is this expected?
Or is there some sort of race condition here?
 
2:14 AM
@JacobSchneider I would think that you are probably having a problem with the pushing the body onto an array. To test it out, check the type using typeof before you pass it to send and after you pass it (right before you send it from the server)
Because it might be sending a (I think) Buffer object
either Buffer or Byte, can't remember what the name is in node vs python
 
Buffer
but it shouldn't be, I've got anti-buffer code
fs.readFileSync('file').toString()
 
that could be part of the problem, you can't just convert to string iirc
you have to convert to base64 I think
705
Q: How to do Base64 encoding in node.js?

murvinlaiDoes node.js have built-in base64 encoding yet? The reason why I ask this is that final() from crypto can only output hex, binary or ascii data. For example: var cipher = crypto.createCipheriv('des-ede3-cbc', encryption_key, iv); var ciph = cipher.update(plaintext, 'utf8', 'hex'); ciph += ciphe...

not entirely positive on that though...
I'd have to get my hands dirty at that point
32
Q: NodeJS base64 image encoding/decoding not quite working

EvanI've been trying to handle saving images POSTed to nodeJS (and the express framework) to a database, and have been having some trouble. Ignoring all the web processing, I think that I've narrowed down the problem to the way base64 encoding is happening in node. I believe that the oversimplified ...

 
I read somewhere that an image needs to be encoded in binary
 
read in one of the answers that binary is deprecated
 
2:19 AM
but who knows how accurate that is until you verify it lol, but everything I've read lately says base64 is the way to go
Maybe the buffer object needs to be passed to the browser
Node might use the http module to implicitly convert that to a binary format
 
perhaps
I'll go and do some further encoding testing
 
easiest workaround to test if it needs to be in a buffer:
check 'Content-Type' and if it's an image, don't "un-buffer" it
 
you might look into TypeScript for a project like this to make things easier
not that I'm one to preach that considering I'm one of it's newest converts lol
 
I've heard typescript is really good, but there's something about it that I just don't like and I couldn't tell you what that is, I just don't.
 
2:26 AM
Yeah... I know what you mean.
 
user8729657
@DavidKamer, it's possible to render your component more than once in the HTML right?
 
@OvieAdese do you mean like reuse it or actually render it?
 
user8729657
yea
 
React I'm guessing?
 
what I'm asking is, what do you mean by render?
because rendering is part of the react lifecycle, but in the context it sounds like you mean reuse
 
user8729657
2:28 AM
yea I mean reuse
 
That's the point of components
You can reuse it as many times as you want.
 
user8729657
ReactDOM.render(<Gotkush />, document.getElementById("checkout"));
 
    <Component/>

    <hr/>

    <Component />
 
user8729657
<div id="checkout"></div>
 
user8729657
i cant do it more than once
 
2:29 AM
oh
yeah, you should probably only do that once if you're making an SPA
The idea is to add components to your root component (or somewhere down the line) in an organized way.
You can mix react with static pages if you want though
 
user8729657
i see
 
so basically, you should be able to have two different elements with react components in them, but you're CSS matters at that point
you'll need CSS in your root html page that has the react components mounted to tell them how to display
 
user8729657
ohhh
 
I mean that's how Facebook, the inventors of React, use React
 
haha yeah
 
2:33 AM
it's funny bc Reddit uses it the way the rest of us do lol
 
hey @DavidKamer I've implemented the stream and It's returning 0B
 
Is it safe to say that in setTimeout(function() { doSomething(); });, doSomething() will only run once Angular's interpolation completes?
 
@JacobSchneider hmm, have you tested it out of your framework to see if it's the code or possible another moving part?
 
I am using MutationObserver to change an attribute of a specific element as soon as it gets rendered. However, that element's tag attribute is set to {{app_value}}. So in my observer, once I detect that this element has been added to the DOM, I run setTimeout(function() { doSomething(); });, where doSomething() then goes and appends something to that element's tag value. However, if I use setTimeout(), is it guaranteed that doSomething() will only run AFTER Angular interpolates?
I guess no one knows :(
 
not many people here do Angular
 
2:41 AM
Doesn't vue.js also have interpolation bindings?
 
idk, I don't do vue, but I could probably help with vue easier than something as opinionated as angular
 
Wherever interpolation happens, I think this question would be relevant.
 
I've never managed to get into angular or vue
 
vue is just less useful react and angular is just react that makes you do exercises in the pointless lol
 
haha that's a good way of putting it
hey another question, I want to pipe my ReadStream into the ServerResponse instance, but I'm not sure whether ServerResponse is actually a stream
 
2:46 AM
"the response inherits from Stream"
so it's a stream with additional properties
 
console.log(ServerReponse instanceof require('stream'))
> true
 
@DemCodeLines but to answer you question to the best of my knowledge, if Angular's interpolation is anything like the react render lifecycle, it depends on how you define the timeout, but generally it would happen after the view is initialized (trying to use generic terms)
@JacobSchneider do you use vscode?
 
@DavidKamer no WebStorm
 
nvm then... there's a really cool extension for vscode I found today that lets you search mdn with a comment in the editor formatted like: \\mdn http.ServerResponse;
you just delete it and closes the window it opened to show you the docs... really cool
didn't test it with node though, just stuff I'd typically use mdn for lol
 
yeah fair enough
 
2:51 AM
maybe there is/should be one for node
 
the node.js docs?
 
yeah
although mdn covers node.js stuff, it's not the best source for node.js api information
 
hm, I'm sure you could fork that extension and modify it
I find most useful information comes from SO
 
probably. I've never used webstorm (at least I don't remember it if I did)
@JacobSchneider and some of the most useless. It balances out pretty quickly if you consider the number of rabbit holes it can take you down
 
I mean, yeah
 
3:09 AM
@DavidKamer How would I implement the stream, It seems to be sending back nothing and the response ends imediately
 
@JacobSchneider I assume the stream is async so how it's called probably matters
odds are it's returning w/o waiting for the stream or something like that, but I've rarely dealt with file streams
 
fs.createReadStream(resovlePath('/res/image.jpg'), 'base64').pipe(response)
 
you have to call .on on the stream and then pipe the output from what I can tell
 
maybe:
fs.createReadStream(resovlePath('/res/image.jpg'), 'base64').on('open').pipe(response)
This is what I'm referring to as an example:
var s = fs.createReadStream(file);
    s.on('open', function () {
        res.setHeader('Content-Type', type);
        s.pipe(res);
    });
which looks convoluted, but I'm sure some of these parts are necessary
and since it's returning 0B, the first problem is probably it not waiting for the file read
and .on seems to be the thing doing that in this example
 
3:15 AM
this.res.doNotEnd();
const stm = fs.createReadStream(file, encoding);
stm.on('data', data => this.res.write(data));
I'm suppressing the end event but still the response is terminated prematurely
that must be the reason
but commenting out the stm.on('data'... does not terminate the response
 
well, you can't pass it to write unless write is piping it I assume
@JacobSchneider wait so what happens when you do that?
 
I've got localhost:1080/res/image.jpg open in postman. and the response doesn't end.
whereas if I have that line, then it terminates imediately
then I replace write with send and it doesn't end, so I add the end event back in and it ends the response, but with no content
the data event is definitely being fired, I'm logging the data it returns and there is definitely data
 
@JacobSchneider what if you just call stm.pipe(res)?
 
does the exact same thing except with write which terminates prematurely
 
well is res a response object with the content-type set?
 
3:21 AM
All information is correct except the body
the MIME is correct, the Content-Length is 0 as to be excepted, but everything else is fine
 
I think the size of the packet is set in the header
or something like that
 
must be
 
maybe the Content-Length property.. been a while sense that came up for me, so maybe a different header "key"
odds are the body is checked through the pipe to add the size to the header with the http module or something like that
 
The Content-Type is definitely correct
I set the Content-Length header myself
 
@KendallFrey Know anything about pneumatic math? Might try and improve on Tom Stanton's compressed air engine.
Powering on multiple strokes, using a real tank, etc.
 
3:27 AM
@JacobSchneider did you check if it's a real thing first lol?
 
yeah
Content-Length is still used
 
yeah, I vaguely remember fixing an issue with it a long time ago
 
@Allenph You know you can get in touch with him? He should build a V8 and have it connected to a compressed air pump rather than a bottle
@DavidKamer I remember being stuck with it for like a whole week
not fun
 
@JacobSchneider I dont want to bug him
I'm sure hes had a million people suggest it already.
 
fair enough
 
3:31 AM
I just want to try it then bug him if it works.
 
yeah that's a much better idea
 
I'd also like to learn how to do the math before I actually spend a fuck ton of time.
 
Who Tom Stanton?
 
YouTube. Its dope.
 
He's so great
 
3:33 AM
ikr, I love it when review brah reads my chats, gives me chills lmao
 
he has literally consumed my YT feed
well, not literally but he's the only thing in it
 
maybe not chills, but still a lot of fun, I feel like my chats/comments are being reviewed by the best reviewer in the world
 
@DavidKamer I've done some debugging and worked out that the send function isn't writing to the return array
 
@JacobSchneider hmm, are you calling pipe anywhere?
 
no, but I'm doing the thing with the res.send rather than write
so basically, yea
no hold up, it's pushing but inaccessible afterwards
Listening on 1080
GET /res/logo.jpg text/plain 200
sending body
pushing
pushing
pushing
you were right
 
3:40 AM
yeah, what is the type of the variable write before it's pushed?
 
which ? the body?
an array
 
an array filled with what?
 
nothing other than strings
 
I wonder what browsers/clients expect with an image MIME type
they might expect a buffer or whatever
 
I've tried the buffer, it doesn't work
 
3:47 AM
Yeah, idk about how you're pushing it into an array.
 
I've just modified the function slightly
http.ServerResponse.prototype.send = function (body) {
	if (typeof body === 'string') {
		console.log('pushing');

		if (!this.wroteHeaders) {
			this.return = this.return || [];
				this.return.push(body);
		} else {
			this.write(body);
		}
	}
};
I keep track of whether or not I've written the headers, if I have, send the body immediately
otherwise, collect it
wait can you write the body before the headers?
 
yeah, that's beyond what I know lol.
 
ah okay
 
I have a question regarding the renderRoutes function from react-router-config.
 
@JacobSchneider I would assume it doesn't matter and if it does it would be a code smell in node
considering you can manually set header fields
!!dontask
 
3:52 AM
in C#, Jul 3 '18 at 19:41, by Kendall Frey
Don't ask if you're allowed to ask a question. Don't ask if anyone's available or knows how to use what you're using. Don't say you're going to post a question. Just ask your question.
 
I reckon that sounds right
 
My question is how does renderRoutes know the given location passed to Route?
 
The <Route> Component has a location prop
my guess is it could be read from that
 
@ZhengquanBai wow, that's such an anti-pattern. I like it lol
 
@DavidKamer The image content is definitely being written to the stream but I can't go from there
 
3:57 AM
@JacobSchneider maybe the stream has to be returned directly when you set the content-type to image
or something like that
maybe the http module then expects a stream (maybe not though, just a guess at this point)
 
the write function takes a buffer or string.
 
You might need to read through the docs to figure this one out.
right, but does the write function do anything with the header?
 
no it's just for the body
 
uhh
you are calling res.end, correct?
 
00:00 - 04:0004:00 - 22:00

« first day (3081 days earlier)      last day (1866 days later) »