Unable to --watch directory with node-dev - node.js

I am trying to watch only specific directories while starting node-dev because of the issue with multiple watches that causes;
Error: watch /usr/src/app/node_modules/common-tags/lib/stripIndent/stripIndent.js ENOSPC
I tried passing the watch flag but, the process is not able to find the module;
node-dev --watch api app.js
It throws the below error:
Error: Cannot find module 'api' from '/usr/src/app'
at resolveSync (/usr/src/app/node_modules/resolve/lib/sync.js:89:15)
at module.exports (/usr/src/app/node_modules/node-dev/lib/resolve-main.js:4:10)
at getConfig (/usr/src/app/node_modules/node-dev/lib/cfg.js:30:16)
at module.exports (/usr/src/app/node_modules/node-dev/lib/cli.js:46:14)
at Object.<anonymous> (/usr/src/app/node_modules/node-dev/bin/node-dev:11:5)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
The api directory is present in /usr/src/app. I tried using the same watch flag with nodemon and it seems to work but it has its own set of issues and crashes when a file change occurs.
I tried putting the configuration in .node-dev.json, but there has been no impact.
{
"watch": ["api"],
"ignore": [
"*.test.js",
"assets/*",
"coverage/*",
"docs/*",
"email_templates/*",
"kubernetes/*",
"logs/*",
"node_modules/*",
"queue/*",
"script/*",
"shared/*",
"tasks/*",
"test/*",
"tests/*",
"uitests/*",
"views/*"
]
}
Please note that I cannot modify fs.inotify.max_user_watches as the VM is shared and I don't have permission to run system commands.
Any help would be highly appreciated.

Related

how can i fix this error that nodemon keep on showing

i following an express.js tutorial andd after some code and functionalities with api requests i followed exactly how he changed the code that handles these requests into a seperate js file in another folder just to clean up the code but after i did that this error showed up
i tried changing the file name , i tried removing the node-modules folder and running npm install again and i tried installing the module with the issue
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/routes/api/members'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (C:\Users\Get_Rico\Desktop\crashcoursse\index.js:11:25)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
[nodemon] app crashed - waiting for file changes before starting...
i expect nodemon to save the changes and work just fine with no errors just like what happened in the tutorial
It appears the error is probably coming from this line of code and it's telling you that it can't find the '/routes/api/members' module file.
And, this would not be working because you're trying to load a local module without a proper path name. If no path is specified, then it tries to load a global or built-in module. If that module is in the current directory, then you should use the correct path:
const yourModule = './routes/api/members';

Google Cloud Function not recognizing Papaparse 5.0 Dependency

I am building a Node.js Google Cloud function, and it is not recognizing the dependency "papaparse":
in package.json
"dependencies": {
"papaparse": "^5.0.0",
"twilio": "^3.33.2"
}
Error code I am getting:
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'papaparse'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/index.js:8:14)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
I have tried reinstalling papaparse, running npm audit, but those steps haven't helped.
Does anyone know why this would happen?
I just managed to deploy a Cloud Function with papaparse.
For this you just need to deploy your function from the Cloud Shell. First create a folder where you gonna insert all your files. Then clone the repo from the papaparse github with the command git clone into that folder.
Now after adding your Index.json and your Package.json you can deploy your Cloud Function following this Deploying from Your Local Machine documentation.

Error: Cannot find module 'C:\server.js' in Node server for Meanjs

I have git cloned meanjs into a folder in D: drive as shown below and ran the command npm start to start the node server.
admin#admin-PC MINGW32 /d/Udemy Angular 1 projects/Project5/jobfinder (master)
$ npm start
> meanjs#0.5.0 start D:\Udemy Angular 1 projects\Project5\jobfinder
> gulp
[23:41:30] Using gulpfile D:\Udemy Angular 1 projects\Project5\jobfinder\gulpfile.js
....and got the below error.
Error: Cannot find module 'C:\server.js'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
[23:58:35] [nodemon] app crashed - waiting for file changes before starting...
After that, just to give it a try I copied the server.js from the current directory to C:\ and issued 'npm start' command at git bash from the same directory and the error changed to below.
Debugger listening on [::]:5858
module.js:457
throw err;
^
Error: Cannot find module './config/lib/app'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\server.js:6:11)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
[23:41:52] [nodemon] app crashed - waiting for file changes before starting...
Can anyone please help me understand why is Node looking for server.js and other resources at C:\ instead of the current directory? Is there anything very simple I am missing out (though I find it quite strange !). Btw sorry for posting the git bash errors as code since I did not have enough reputations to post more than one image link.
Cheers!
Adding my research ....
Invoking 'npm start' command in meanjs directory hits the file gulpfile.js. Looking into the file, I saw that a gulp task (nodemon) was initiated as below and the script property of the return object was set to 'server.js'.
Code from gulpfile.js.
gulp.task('nodemon', function () {
var nodeVersions = process.versions;
var debugArgument = '--debug';
switch (nodeVersions.node.substr(0, 1)) {
case '4':
case '5':
case '6':
debugArgument = '--debug';
break;
case '7':
debugArgument = '--inspect';
break;
}
console.log('nodemon task'); // checking execution of the callback
return plugins.nodemon({
script: 'server.js',
nodeArgs: [debugArgument],
ext: 'js,html',
verbose: true,
watch: _.union(defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
});
});
The above problem was solved by deleting the Autorun string in the registry at the below path.
"HKEY_CURRENT_USER\Software\Microsoft\Command Processor".
The autorun string was set to C: and as a result Nodemon recognised C: as the root instead of the current directory in Gitbash or command prompt.

Error pointing to non-existent file when running Node.js app locally

I was just sent the files for a Node.js app (which is working without issues online) and I'm trying to set it up on my Windows machine.
I have Node server running, but I'm stuck trying to actually load the app. I can navigate to the directory with the Node command prompt, and there's an app.js (plus folders like config, components etc) in there which I've been trying to run, but I am getting the following error:
D:\my-directory\game-master>node app.js
module.js:327
throw err;
^
Error: Cannot find module 'config'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (D:\posao\aktivni projekti\smart rebellion\game-master
\app.js:7:10)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
The thing is, there is no file titled module.js in the directory. I presume it's a built in Node.js file, but then how do I troubleshoot this?
My best reading of the error is that there should be a config.js file somewhere, but that doesn't make sense because these same exact files work with no hickups on a remote server.
If you want to require('./config'), where config is a directory, the file ./config/index.js should exist.
You can't require('config') however, because node.js will try to find it in node_modules.
Check out node.js modules documentation where the require algorithm is well explained.

Getting 'Could not find configuration for port' Error starting N|Solid Proxy

I'm getting the following error trying to start the N|Solid proxy
Daves-MBP:proxy-3.2.2 davblak$ npm start
> nsolid-proxy#3.2.2 start /Users/davblak/proxy-3.2.2
> nsolid proxy.js
/Users/davblak/proxy-3.2.2/proxy.js:9
throw new Error("Could not find configuration for port")
Error: Could not find configuration for port
at Object.<anonymous> (/Users/davblak/proxy-3.2.2/proxy.js:9:9)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:149:18)
at node.js:985:3
I do have the etcd service running - any thoughts?
On your proxy-3.2.2 folder you need to have a .nsolid-proxyrc file with configuration options for your proxy, can you confirm if the file is in there?, if not this file should look like:
{
"registry": "localhost:4001",
"port": 9000,
"denied": [],
"broadcast_approved": [
"ping",
"process_stats",
"system_stats",
"system_info",
"info",
"versions",
"startup_times"
]
}
Ah, that is the issue. I think I realized how this happened. After downloading the files I went into the directory and copy/pasted the files via Finder. As Finder doesn't by default show . files I didn't copy the .nsolid-proxyrc file.
I blew away my directories and tried again; this time I copied the entire directory at the folder level. Using ls -al I now see the .nsolid-proxyrc file in there and the proxy works. Thanks for all the help!

Resources