Currently, I am in the process of developing an npm module and conducting tests before making it available to the public. The method I am following is outlined in a blog post found at this link. However, I am encountering difficulties when trying to require even a basic module. Below is my package.json file:
{
"name": "mystuff",
"version": "0.0.1",
"description": "",
"main": "./lib/index",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT"
}
Additionally, here is the very simple index.js file that I am working with:
'use strict'
exports.test_call = function() {
return "Hello Module"
}
My expectation was that I could simply require my module, but unfortunately, this has not been successful:
> require('mystuff')
Error: Cannot find module 'mystuff'
at Function.Module._resolveFilename (module.js:327:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:355:17)
at require (internal/module.js:13:17)
at repl:1:1
at REPLServer.defaultEval (repl.js:252:27)
at bound (domain.js:281:14)
at REPLServer.runBound [as eval] (domain.js:294:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:83:20)
Despite the unsuccessful attempt to require the module, it seems that the installation location is correct, and the module functions as intended when required from its specific directory:
> require('./node_modules/mystuff')
{ test_call: [Function] }
> require('./node_modules/mystuff').test_call()
I am puzzled by why I cannot require the module directly. What could be the missing piece of this puzzle?