Node.js Service Registry – Code Review Stack Exchange

  register(name, version, ip, port) {
    this.cleanup();
    const key = name + version + ip + port;

    if (!this.services(key)) {
      this.services(key) = {};
      this.services(key).timestamp = Math.floor(new Date() / 1000);
      this.services(key).ip = ip;
      this.services(key).port = port;
      this.services(key).name = name;
      this.services(key).version = version;
      this.log.debug(`Added services ${name}, version ${version} at ${ip}:${port}`);
      return key;
    }
    this.services(key).timestamp = Math.floor(new Date() / 1000);
    this.log.debug(`Updated services ${name}, version ${version} at ${ip}:${port}`);
    return key;
  }

I thought the code looked kinda amateurish. I am not sure if I am imagining things. Isn’t there a better way to assign values, also what about how the key is made, shouldn’t we use a random string generator or at least encode it after appending the values? What’s the best practice?

https://github.com/bluebrid/base-knowledge/blob/317bcdacd3a3806a6f98f05a7660dc97c506e8fb/javascript/advance/microservices/demo.1/service-registry/server/lib/ServiceRegistry.js