Access NPM packages in development console


Reading through the documentation on Hacking Atom there’s an example of downloading and installing an NPM package. In the source code the library is available like so:

figlet = require ‘figlet’

Can a library be accessed through the Chromium development console somehow? A plain var figlet = require('figlet') does not work, but it would reasonably be available somehow. In a browser environment libraries attach themselves to the window element, can a nested atom component be accessed that contains any dependencies required by your package?


You can use var figlet = require('/absolute/path/to/figlet'). The directory require looks in for modules when used from the dev console is the Atom install dir. So unless you install the module in some parent path of the Atom install directory, you’ll have to use absolute paths.