Load an npm module through dev console


#1

I like to test out code snippets in the dev tools console as I’m working on plugins.

How can I properly require modules into the console?


#2

I’m a bit surprised there has been no answer to this as it’s a useful idea.


#3

fs = require('fs') works. Just keep in mind that the JavaScript console in the Developer Tools is a JavaScript console, not a CoffeeScript one.


#4

Thanks @leedohm, but I want to require modules in my package, not just the core node modules.

But if I require("module") that is in my package.json (and installed) I get an error Cannot find module 'module'


#5

Since the console isn’t executing code from the same directory as the package, you probably need to use the full path. What about require(atom.packages.resolvePackagePath(<name>) + "node_modules/<module>")?