question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider adding a factory method

See original GitHub issue

I know it’s “idiomatic”, but I’ve never been a fan of this style for requiring a class that will only be instantiated once:

const Conf = require('conf');
const config = new Conf();

What about adding a factory method like this:

const conf = require('conf').new();

or even:

const conf = require('conf')();

This could be supplemental to the existing instantiation behavior.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mceachencommented, Sep 23, 2016

somewhat related: this isn’t a great first impression:

$ npm install conf
$ node # NEW TOY OMG SO EXCITED
> const Conf = require('conf')
TypeError: Path must be a string. Received null
    at assertPath (path.js:7:11)
    at Object.dirname (path.js:697:5)
    at Object.<anonymous> (..\node_modules\conf\index.js:13:24)
# sad trombone 😢

because node’s REPL has no module.parent:

$ node
> module.parent
undefined

(and exposing a constructor would let me feed conf what it needs)

My current environment:

$ node -v
v6.6.0
$ uname -a
MINGW64_NT-10.0 xps15 2.5.0(0.295/5/3) 2016-03-31 18:47 x86_64 Msys
0reactions
zekecommented, Sep 26, 2016

These styles won’t work for ES2015 imports

Good point. Not on that 🚋 yet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Factory Method - Refactoring.Guru
Factory Method is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the...
Read more >
Factory Method Design Pattern - SourceMaking
If you have an inheritance hierarchy that exercises polymorphism, consider adding a polymorphic creation capability by defining a static factory method in the ......
Read more >
The Factory Method Pattern and Its Implementation in Python
The new design of Factory Method allows the application to introduce new features by adding new classes, as opposed to changing existing ones....
Read more >
Factory method design pattern in Java - GeeksforGeeks
The factory design pattern says that define an interface ( A java interface or an abstract class) for creating object and let the...
Read more >
Factory Pattern. When to use factory methods? - Stack Overflow
Factory methods should be considered as an alternative to constructors - mostly when constructors aren't expressive enough, ie.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found