-
Lewix
hi
-
Lewix
sorry i had issues logging in
-
daysun
can npm install themselves into other packages?
-
daysun
without scripts.
-
daysun
got ignore-scripts=true. Can their "unpack path" be into other modules?
-
cek
is there any way to create a pending promise and pass it reference to some code that will complete it once it's ready? In current js' way, you have to define the resolution function during creation. That is, you can't create an "unbound" promise object.
-
_rgn
> you have to define the resolution function during creation
-
_rgn
you do?
-
cek
-
cek
that is, I need the Q way: `return Q.defer().promise`
-
joepie91
cek: a 'defer' is what you're looking for, for which you can use Promise.defer if using Bluebird, or the `p-defer` module if using ES6 Promises -- though the usual warnings apply, only do this when you *really* have no other reasonable way to express your code (eg. it's task queue code), because it's easy to get wrong and hard to follow
-
cek
it's a dispatcher code, a state routing machine if you will
-
cek
but I got the idea, no built-in.
-
joepie91
that sounds like it could be a valid case for defers, yeah
-
_rgn
there was a library that would log all require calls for debugging purposes. can't find it
-
joepie91
_rgn: isn't that doable with just the NODE_DEBUG env var?
-
yaalon
Hello. I recently began working on a colleague's project. I reorganized it a bit, and have broken the main project test-- just a couple parts of the test. But I am getting this error and I don't quite understand why.
-
yaalon
" getaddrinfo ENOTFOUND undefined"
-
yaalon
I read that it may have something to do with a malformed "http" vs "https" notation or something like that...
-
joepie91
yaalon: that's a DNS lookup error, means that a DNS request was made for a non-existent domain/hostname
-
joepie91
malformed URLs are one possible cause of that
-
yaalon
Thanks a bunch! Interesting
-
joepie91
eg. if you have a URL like this: http//example.com/bar
-
joepie91
(note the missing : colon)
-
joepie91
then it may parse that as the domain "http" (which doesn't exist) and a path of "//example.com/bar"
-
zsoc
In other words, if you refactored any parts of the code that builds a url, look there :p
-
yaalon
Great to know. I thought it could be something like that, so I am very glad to have your input & validation of that
-
yaalon
you folks rock
-
joepie91
if the cause is not obvious, I would recommend logging the result of url.parse on whatever URL you are trying to access in the code that fails, and seeing whether the hostname is what you expected
-
joepie91
it can of course also just be that the domain really doesn't exist :)
-
yaalon
Ugh. I think I see what is happening. My company/team uses OOP. So, in this project, there's the real world object, which connects to an enterprise app. Then, we test that object... but using the sandbox account instead of the live production account. I extracted some functions from the main real world object, and those functions rely on the main real world object... yet those functions are also used in the test objec
-
yaalon
t
-
yaalon
This is why I don't like OOP -- things are tied together
-
Kingsy
can someone help me understand something, so, I have this version of node installed -> nodejs-14.15.4_1 <- however, I also have nvm installed. SO when I open bash and type node -v I get v12.19.0, when I do it in any other terminal (fish or elvish for example) I get v10.10.0... how? evlish and fish shouldnt have nvm working on them anyway. where is the node version determined?
-
joepie91
yaalon: that sounds like "bad OOP", not "OOP" :P
-
yaalon
Yeah... I think you're right. OOP isn't necessarily the culprit. I just prefer functional programming so I can keep clear separations between __everything__ and not make things dependent mounting functions on objects
-
joepie91
Kingsy: if you use fish/elvish' mechanism for determining where a certain binary/command comes from, what do you get?
-
joepie91
in Bash it'd be `type -a` or `which`
-
Camilo
ok, I have a stupid question... how can I save the result of a sql query to an object, or is that a bad idea
-
Kingsy
moment
-
Kingsy
joepie91: /usr/local/bin/node
-
zsoc
Camilo: it's already an object
-
Kingsy
and that gives me v10.10.0
-
joepie91
Kingsy: have you ever used `n`?
-
joepie91
maybe before trying nvm
-
Kingsy
what do you mean?
-
Kingsy
nvm isnt even available on the prompt.
-
Kingsy
weirdly, according to me package manager, it installs it here -> /usr/bin/node <- so how its going for /usr/local/bin/node first, is the mystery
-
samsch
Presumably to have the result you described, you have Node installed at least three different ways.
-
Kingsy
samsch: exactly.. which is just mental.. :D I mean I do have nvm. which is great, but I don't want it to be used outside of bash
-
samsch
If the nvm Node is being used, `which node` (or equivalent) will show a path with nvm in it, from your user folder. My guess is that nvm in bash just needs you to add the nvm .bashrc stuff.
-
Kingsy
yeah Ih ave done that. so nvm works in bash, but my default terminal is elvish, so I would expect when I run node -v there it would be the OS version of node, not nvm related.
-
samsch
If you did the `nvm use system` thing or whatever though, that could also let you see the non-nvm path to node in bash.
-
samsch
That sounds like it's already doing that.
-
samsch
But that you have two OS versions of Node.
-
Kingsy
elvish isnt ANSII you see, so I cant interact with it within this shell
-
Kingsy
samsch: hmmm wow. perhaps!
-
Kingsy
I don't see how I can, unless it was installed via npm or something.
-
samsch
I think that was the reason for joepie91's question about having used `n` in the past, because it can have that result.
-
Kingsy
alright, let me seeeee
-
Kingsy
holy crap thats it!!!
-
joepie91
right, I mentioned `n` because it messes with globally-installed Node, and is usually the cause for this specific problem :)
-
Kingsy
right this is getting removed then
-
joepie91
and a lot of people try `n` before they try `nvm` and then forgot they ever used `n`, and only discover later that `n` messed with their global environment
-
joepie91
when they try to use a system Node
-
samsch
`n` acts too much like malware :/
-
samsch
It's like one of those "technically correct" solutions that's just wrong.
-
Kingsy
well there you go. I am back on v14.15.4
-
Kingsy
I never ever would have remembered that.
-
Kingsy
thanks so much joepie91 and samsch
-
joepie91
good to see it solved :)
-
» joepie91 resets the "days since n screwed up someone's system" counter to 0
-
samsch
sad trombone noises
-
Camilo
clearly I'm a bit slow because I still can't seem to access my sql result object outside of sql callback function
-
samsch
Camilo, You'll need to do your work inside the callback. (And hopefully in a Promise .then() callback rather than directly passed)
-
Camilo
samsch: thanks, I am working towards that now.
-
Camilo
banging my head against the wall because I broke my sql query somehow
-
Camilo
do you know if it is ok to nest queries inside of callback functions of other queries?
-
zsoc
You probably don't want to. Use promises, let the caller get back the data or the transformed data in its own .then(), pass the data to another function from there if you have to
-
zsoc
break it down into single functions that each to one thing
-
zsoc
!paste @ Camilo
-
ecmabot
Camilo: Please paste your code to a site like
gist.github.com or
dpaste.org (NOT pastebin.com or hastebin), or create a running example: see !fiddle. See also !badpastebin !hastebin !nopaste and !mcve
-
zsoc
also if you gist the code we can give you more specific advice
-
Camilo
ok thanks will add some comments and upload, very kind of you!
-
yaalon
Does adding OOP keywords-- Class, Public, Private, Static... feel like nodejs is getting turned into java/an OOP language to anyone else?
-
zsoc
Dunno, I just don't use any of them :)
-
yaalon
I guess it just allows an OOP way of using nodejs... but it's a bit weird to me... why not just use an OOP based language to use OOP stuff?
-
yaalon
zsoc: glad I am not alone on that. but now I am thrown into an organization & team which apparently all use OOP and want to sort of "do things as they've always been done here"
-
Camilo
-
joepie91
yaalon: yeah, I'm not a fan of the class scope creep either
-
Camilo
struggling with the "todo" part, imo the easiest solution is to make 3 different SQL quiries, but maybe thats not a goo idea
-
joepie91
yaalon: it's all basically unnecessary because lexical scoping pretty much already does all of this?
-
joepie91
but people insist on using their damn classes :(
-
ljharb
yaalon: JS is not adding "public" or "private" keywords.
-
ljharb
yaalon: that's part of typescript.
-
ljharb
the `class` keyword, while badly named is an eminently superior way of doing inheritance in JS than previous alternatives. it's just that inheritance itself sucks.
-
samsch
And what *would* have made sense is to deprecate doing inheritance at all
-
samsch
but noooo
-
ljharb
that would never have been even remotely possible
-
yaalon
I worked with Clojure a bit about 2 years ago. And my goodness, separating functions from data seems to frikkin intuitive. Having data objects & functions in javascript seems so much easier to grok than tying functions and data into objects... because then you're stuck with those objects-- it's hard to break them down once they get built up.
-
yaalon
so* intuitive
-
ljharb
yaalon: that's accurate
-
ljharb
yaalon: but that's not an argument for making inheritance codebases less terrible
-
yaalon
So much simpler than using all these funky keywords...
-
yaalon
argh. lol
-
ljharb
*for not making them less terrible
-
ljharb
yaalon: again tho there's no public or private keywords
-
ljharb
in JS, everything reachable is public, everything unreachable isn't. class private fields use `#` to indicate that the fields aren't reachable from outside the class body
-
yaalon
ljharb: thanks! glad to have that clarification. I was confused because I was reading about them here--
sitepoint.com/javascript-private-class-fields
-
yaalon
-
yaalon
but I see that it's a new/experimental feature
-
yaalon
Lol... Ugh I just don't want to see people adding [what seems to be] Ruby & Java concepts into NodeJS and turning it into those languages lol
-
ljharb
yaalon: public class fields are automatically public, like all object/class properties
-
joepie91
ljharb: wasn't JS adding public/private *syntax* though?
-
ljharb
yaalon: it may help you to know that private class fields are unique out of every language on the planet
-
yaalon
Awesome ljharb. It's so awesome that the language developers such as yourself & other folks are here to chat with
-
ljharb
joepie91: not really no
-
joepie91
yeah that
-
ljharb
public fields are just normal field syntax
-
ljharb
it's not the public/private keywords. public fields are just normal per-class properties
-
zsoc
@Camilo: sorry i got pulled into a meeting, i can look at it in a few if you stick around
-
ljharb
but JS is the only language i know of that has *actually* private class fields.
-
ljharb
yaalon: ruby and java both let you break encapsulation whenever you like
-
yaalon
brb, going to a cafe to get some grub. Ill. be back in 10 minutes. and ill try to find the log of this convo so I can keep up
-
Camilo
@zsoc: thanks, I'm just reading up on promises at the moment, appreciate being steered in the right direction!
-
saml
in dockerfile, do you have CMD to run npm start? or just run node ... ?
-
GreenJello
saml, often `npm start` will run the development server
-
GreenJello
so either a separate script or `node …`, in the common case
-
saml
it's a bit awkward. this project does npm start in docker because prestart does sequelize db:migration.. hrm what disaster can happen when multipel containers run db migration at start?
-
GreenJello
you should run the migration as a separate container
-
saml
yeah.. not sure why app does migration
-
GreenJello
it might be the same docker image, but with a different command
-
saml
maybe it's easier in docker-compose to synchronize migration && running node app
-
saml
if migration were in different container, node app container still needs to wait for migration container to complete
-
GreenJello
I've only worked with kubernetes for container orchestration, and there I can run a "job" and wait for it to complete
-
GreenJello
you could do something similar with ssh + docker commands. Not sure about other orchestration tools
-
AAA_awright_
Is there any well-supported library to make MySQL queries that supports promises?
-
joepie91
AAA_awright_: doesn't mysql2 do that?
-
AAA_awright_
Isn't that an unofficial library? I ask because I just ran into an issue with the connection pool that pretty much makes it unusable
-
joepie91
AAA_awright: all libraries are "unofficial", AFAIK :)
-
joepie91
have you filed a bug?
-
AAA_awright
Yeah, and regression
-
joepie91
in that case, use an older version?
-
AAA_awright
And I mean, more or less, some more on the more-unofficial side
-
tu
I'm trying to upgrade a project from node12 to node14. It's an express webserver. Everything seems to work except in one spot where I pipe a file stream to a response. This works under node12 but fails under node14. I'm totally lost as to why. If I manually listen for the data and end events from the stream and write to the response it works as well. It's only when I try to pipe directly to the response that it fails. Can
-
tu
anyone think of any node changes that could have caused this? Or even a place to start looking for what I'm doing wrong? I've been chasing this for like two days without much success (other than finding that manually writing worked)
-
joepie91
tu: can you pastebin/gist the code?
-
tu
-
tu
It's in an app.use instead of app.get but it's basically that simple.
-
tu
Also tried using the npm send module (which expressjs uses for serve static) and it acts the samw
-
joepie91
tu: can you gist/pastebin your *actual* code? :)
-
joepie91
problems are often in unexpected subtle places
-
tu
-
tu
All the commented out code is other things I've been trying
-
» joepie91 looks
-
tu
70-78 works. As does 57/58
-
joepie91
tu: when you say it 'fails', what do you mean exactly?
-
tu
When the browser requests it, it just hangs and never responds and is eventually r
-
tu
Timed out on the browser side
-
tu
Node sees the request successfully complete with a 0 content length
-
tu
Also keep in mind this works in node12 exactly as is and only starts failing under node 15
-
tu
Er node 14
-
joepie91
very odd
-
joepie91
it smells like a Node bug but it seems too-fundamental functionality to be broken like that
-
joepie91
are you on latest 14.x?
-
ljharb
tu: still fails in node 15?
-
tu
Yes. Downloaded it yesterday
-
ljharb
it might be an intentional breaking change in node 14.
-
tu
Have not tried node15 that was a typo.
-
tu
It's weird though because the same route works fine when called in the browser
-
tu
So as much as I'd love to blame it on node (because I'm so sick of debugging this at this point heh) I remain unsure
-
joepie91
tu: "works fine when called in the browser"?
-
tu
The route works fine if I hit manually in a browser
-
joepie91
as opposed to?
-
ljharb
in the browser it likely uses a streams polyfill, which may not have updated to account for node 14
-
tu
It only seems to die when my browser app requests it
-
ljharb
ah. are the headers different in those two scenarios?
-
» joepie91 suspects content type negotiation
-
tu
By headers do you mean request or response?
-
ljharb
tu: request
-
tu
Hrm. I don't think content type stuff because I can trace into the server code and see it reach the path where it opens the file and starts to pipe it back
-
tu
Both paths definitely lead to it trying to send the file. Just manually the browser downloads it, where as the js client times out after 10 seconds
-
tu
Note the browser response happens instantly so it's not just a slow route
-
joepie91
tu: adjusted suspicion: there's something weird about how your JS consumes the response (eg. the rate at which it does so), the interpretation of which on the Node.js side was changed from 12 -> 14
-
joepie91
I think the slow HTTP request attack mitigations were longer ago than that?
-
tu
The only weird thing is toggling the node version back fixes it
-
joepie91
tu: I would definitely read the 13.0.0 and 14.0.0 changelogs to look for anything that changed in the http implementation, especially surrounding timeout handling, attack mitigations, etc.
-
tu
I don't really own the code that is trying to do the download. Lemme see if i can find it and see if it's doing anything weird
-
joepie91
that also helps :)
-
tu
From the minified version it looked like a standard request and settimeout handler.
-
tu
I'm so baffled as to how a now change could even cause this.
-
tu
Especially when I can manually stream the file out / read it synchronously and it starts working
-
joepie91
I'm honestly not sure either
-
tu
Fwiw the browser side is basically just.
-
tu
Er basically just hls.js so it's not just some random code it should be a reasonably done heh
-
Kaivo
Is it normal to have a readStream.pipe on both line 105 and 111? What's the behavior when doing that?
-
tu
Oh no. That's just cruft from the copy paste.
-
Kaivo
Ok, nvm then. That's what I assumed.
-
tu
I updated the gist and fixed that and added one other tid bit. I added a handler for the end event on the stream and curiously enough it never fires
-
tu
So I think part of the problem is something around the stream never being closed or something because it never seems to fire events like it was
-
tu
Ooohhh. I think I am starting to narrow something down. My code works with the last version of 13.14.0 so something after that is causing my issues. Now I can narrow it down at least
-
joepie91
tu: it's odd, because end-of-streams *should* be passed through with a pipe
-
joepie91
tu: out of curiosity, what happens when you use streams.pipeline?
-
joepie91
-
tu
One sec will try that
-
tu
Stream pipeline fails the same way and my callback for it is never actually called.
-
Camilo
another stupid question: if I put my functions in a module, how do I access the objects in my main program? Do i need to also include them in the modules?
-
tu
So it works with the last version of 13.x and starts failing in 14.0.0
-
zsoc
Camilo: sorry again, today turned into a mess lol. So one way people do it is by making their modules parametric (return a function that takes parameters and returns the module)
-
zsoc
Camilo: So like if you have a module that needs your db client, you can do `const createFoo = require('./my-foo'); const foo = createFoo(db); Or maybe pass it an object with all stateful deps instead of just the one individually (So it's extensible)
-
zsoc
Camilo: this is an example of that pattern with an express router, but ofc you can use it with anything:
gist.github.com/jkantr/b3706357a831108579bb0f152b7768cb
-
Aeg
Hello,
irc.mesgul.net:8337 How can I solve the character error ?
-
Aeg
Hello,
irc.mesgul.net:8337 How can I solve the character error ?
-
rayyyy
hi
-
rayyyy
are there any reporting engine in Nodejs?
-
tu
Apparently disabling keep alive fixes my weird pipe streaming issue.