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
Marco Vinicio
@Mark-B-88
@kingsleykbc As far as logic, nested is much better because it's more detailed. So if you're working in a team, or you need someone to help you with your code, the nested approach makes more sense. As far as performance, that's something I've not entirely sure about.
Andres Mazzo
@andresmazzo
@kingsleykbc i agree with @Mark-B-88 . Performance could be a little more on nested objects due to serialization of json, which increase cpu load. But it only applies for high traffic and big objects to see a significant variation
Anyabuike Kingsley
@kingsleykbc
@Mark-B-88 , @andresmazzo Thanks a lot
Phuong Nguyen
@neunygph
this is the most active channel I have seen
Salathiel Genèse
@SalathielGenese
NodeJS 17.0.1 error (latest, Linux, x64)
$ node -v
bash: /home/salathiel/.local/bin/node/bin/node: cannot execute binary file: Exec format error
Jordan Harband
@ljharb
why are you installing node with something that's not nvm
Salathiel Genèse
@SalathielGenese
The habit, I guess - tar -xf archive -C target/
I just tested with v17.0.0 and no problem with that
Jordan Harband
@ljharb
tbf i don't have linux, but nvm install 17 worked fine on 17.0.1
Salathiel Genèse
@SalathielGenese
okay
zillerium
@zillerium
I want to setup class vars in nodejs, like you have in Java etc. I am seeing only the constructor, here is a code example -
class myclass {
    var carMake = 'Ford'

}
Jordan Harband
@ljharb
@zillerium a) do not strive to make anything like java, that's always a downgrade. b) class in JS is not really classes, it's good sugar for making a constructor function and a prototype object. a "class var" is probably meant as a static property on the constructor function.
you can't declare variables inside a class body, it's not a scope.
so you can do class X { static make = 'Ford'; } if you want
zillerium
@zillerium
@ljharb thanks
Jordan Harband
@ljharb
that's public tho
zillerium
@zillerium
what is public?
Jordan Harband
@ljharb
you can do class X { static #make = 'Ford'; } for private.
"public" is "reachable" - things on the outside can see and change it
"private" is "unreachable" - and unlike every other language, private in JS actually means private; there's no reflection mechanism whatsoever
zillerium
@zillerium
I was about to edit my code snippet with a method or func to update carMake, eg setCarMake(carMake){ this.carMake = carMake; // but not in a constructor}
Jordan Harband
@ljharb
and there's no "protected" because that concept doesn't make any sense in JS; things are either reachable or not
sure, you can do that in either case. but it makes more sense to have it be private if you want to provide a setter function
that way nobody can set it a different way
however, classes (like for most things) are not a great way to model cars, since they aren't an inheritance tree. they're more like a collection of traits and metadata.
zillerium
@zillerium
cars are just an example, I am not actually working with cars, but I did see a lot of car models in OO systems
Jordan Harband
@ljharb
sure, but most of those are bad examples that only really exist in university :-)
zillerium
@zillerium
to summarise, I can instantiate the class and set variables via the constructor but I cannot have just variables in the class which are modified by functions (eg setters and getters)?
Jordan Harband
@ljharb
you can have properties, but not variables
variables can only exist in a scope, and a class body isn't one
zillerium
@zillerium
About cars, there were commercial examples.
ekranoplan
@ekranoplan:matrix.org
[m]

to summarise, I can instantiate the class and set variables via the constructor but I cannot have just variables in the class which are modified by functions (eg setters and getters)?

I think this would accomplish what you're trying to do:

class Car {
  #fuel = 0;
  #make;

  constructor(make) {
    this.#make = make;
  }

  get make() { return this.#make; }

  addFuel(quantity) {
    this.#fuel += quantity;
  }
}

In this case, #fuel is a private "variable" that can be modified within functions (e.g. the addFuel method). Technically #make is also a variable but I have easily written it in such a way that you cannot modify the make after the car has been constructed (since a Corolla will always be a Toyota) - there is only a getter for the make and no setter, and the #make field is private so it's not exposed to clients.

Zerounodue
@Zerounodue
@zillerium if you come from java you might like Typescript :) have a look https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-oop.html
zillerium
@zillerium
Is there a way to use async/await when a nodejs api server starts up (toload some vars from a file, eg json). I get an error when I tried and just place that at the start of the program because it says I cannot use await outside of an async function. My aim is only to load some variables once only (the json objects are very large and cannot be just coded into the source code and also they could change.
Stephen James
@sjames1958gm
Top level await is available in node 14
Jordan Harband
@ljharb
only in native ESM.
(which should generally be avoided)
1 reply
Salathiel Genèse
@SalathielGenese
@zillerium , i usually do
( async () => {
  // conf
  // start
})().catch( logger.error );
Jordan Harband
@ljharb
native ones should be
and because the tooling and ecosystem is just not ready yet
authoring ES modules is fine, but then you can use babel to transpile.
flyingCodeMonkeys
@flyingCodeMonkeys
Hi guys is anyone familiar with cheerio? i am trying to get the titles of webpages not sure how to select it though
Micule
@Micule
Hello everybody
Meir Shamay
@may215

Hi, I create a npm package that contains several utils for my project, one of the util is a patch to another npm package. Now, I don't know how to export and import the patch in order to use inside one of my projects. This is the example of the patch. file name: patch.ts inside my custom_npm_package

declare module 'node/module/to/patch' {
  interface Manager {
    saveOne<Entity>(entities: Entity, options?: SaveOptions): Promise<Entity>
  }
}

Manager.prototype.saveOne = function <Entity>(
  entity: Entity,
  options?: SaveOptions,
): Promise<Entity> {
  console.log('do things')

  return this.save(entity, options)
}

When this patch is inside the project I want to use it, it's working, I can call to saveOne method.

node.js.developers.kh
@nodejsdeveloperskh

is there anyone who was deploy a node.js web application on heroku successfully?

I tried multiple times (with heroku CLI and connect to GitHub), I also removed the buildpack and add it again but no difference. Heroku seems could not deploy it successfully. would you like to help me?

This is the GitHub Repo: https://github.com/nodejsdeveloperskh/passport-lookup
and this is the Heroku log:

timestamp app[api]: Build started by user X
timestamp app[api]: Release v3 created by user X
timestamp app[api]: Deploy ecba21a1 by user X
timestamp app[api]: Scaled to web@1:Free by user X
timestamp app[api]: Build succeeded
timestamp heroku[web.1]: Starting process with command `npm start`
timestamp app[web.1]: 
timestamp app[web.1]: > passport-axios@1.0.0 start
timestamp app[web.1]: > node index.js
timestamp app[web.1]: 
timestamp heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
timestamp heroku[web.1]: Stopping process with SIGKILL
timestamp heroku[web.1]: Process exited with status 137
timestamp heroku[web.1]: State changed from starting to crashed
timestamp heroku[web.1]: State changed from crashed to starting
timestamp heroku[web.1]: Starting process with command `npm start`
timestamp app[web.1]: 
timestamp app[web.1]: > passport-axios@1.0.0 start
timestamp app[web.1]: > node index.js
timestamp app[web.1]: 
timestamp heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=passport-llokup.herokuapp.com request_id=da8ab014-3902-4d67-9004-c744059279c2 fwd="116.203.217.173" dyno= connect= service= status=503 bytes= protocol=https

But no response in the browser. whereas it sends me the correct response in the localhost

Lorenzo Sandini
@lsandini
Hello all, this might sound like a strange question, but here it is. Is it possible to trigger the server-side execution of a js script, by sending a HTTP POST request for example from a website or from another node app on a different server ?
Lorenzo Sandini
@lsandini
I'd like to pass a date (in the past or future) to my server using an express "app.post" route, on which a script executes a sequence of async functions resulting in a json file. That json file is served through an app.get route on the same server.