Mongoose on c9 how to fix - node.js

I didn't close my mongod when closing the laptop and now its giving me an error. On top of that, I delete the mongod data directory with all my data in it. Now I can start up my apps using node js - is there anyway to fix this or do I need to redo all my app.js again?
Error: Cannot find module '/home/ubuntu/workspace/RESTful/RESTful
Routing/RESTfulBlogApp/cats.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3

All the files which are required in your node app must be present at the time of execution.
As per the error, it is unable to find cat.js in the required folder. You need to create again all the required files, and if they were your dbSchema, i would suggest you create your schemas again before running the app.

Related

NestJS microservices "Cannot find module"

So, I'm trying to create my first microservice using NestJS, but the moment I try to run it, the service stops with this error:
[13:39:21] Found 0 errors. Watching for file changes.
Error: Cannot find module 'C:\Users\voryi\IdeaProjects\YWA\des_server\services\learning-service\dist\main'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
there's no main.js file in the first level of your dist directory. You can define the entry file by adding this to your nest-cli.json:
"entryFile": "learning-service/src/main"
the default is main
try npm run build and then restart your service
I use monorepo setup and this issue happens whenever I start the nestjs server from non-root folder by mistake.
Usually, removing the dist folder and restarting the nestjs server works for me.
In my case, the main.js file was inside src folder so I had to change the script to:
"start:prod": "node dist/src/main"
maybe simply use this inside the project,
npm i #nestjs/microservices

Node JS error: Cannot find module '../build/jvm_dll_path.json'

I am receiving the following error after running npm start:
Error: Cannot find module '../build/jvm_dll_path.json'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/opt/stature-gqdss/node_modules/java/lib
[nodemon] app crashed - waiting for file changes before starting...
Can you help me with this issue?
First, you should check if the server is already running and kill the existing server. If no other server is running, try reinstalling your dependencies and try again.
npm install
I have a hack here. You can simply create a file named jvm_dll_path.json inside node_modules\java\build and paste the path of server to this, between quotes like shown below..
";C:\\Program Files\\Java\\jdkX.X.X_XXX\\jre\\bin\\server"
For me running
node postInstall.js
in the node_modules/java folder worked.

Change node path to current directory

I was trying to run this command from my user directory
NODE_ENV=~/Public/project node socket.js
But it return this error
Error: Cannot find module '/home/user/socket.js'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:418:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:533:3
The thing is i do not want to change directory. Is it possible to do that? And why this is happening?
NODE_ENV is, by convention, the type of environment you're running in, e.g. Development or Production or Test. It only matters for modules that inspect it and set options accordingly, e.g. Many loggers will default to more verbose in development.
Not really sure why you wouldn't just change directories, but your call to server.js can be an absolute or relative path. If the file is in the /home/user/project folder, you can (from /home/User) just call
node ./project/socket.js
After a little mor research, i found this
And according to that site, i have to do this
export NODE_CONFIG_DIR=/home/user/Public/project/config
and run this
node ./Public/smart-backwall-server/socket.js

Error deploying node js app onto Cloudbees ClickStart

I'm trying to deploy a node app onto the Cloudbees ClickStart.
I've create a node js ClickStart (this creates the jenkins job, git repository and application container).
Zipped up my app, then deployed using the Cloudbees SDK.
bees app:deploy -t nodejs -a nodeshort -v nodeshort.zip
When I try to access the URL the application is deployed on I get a 502 Bad Gateway.
Checking the application logs, I see the following printed multiple times:
module.js:340
throw err;
^
Error: Cannot find module '/mnt/e1/genapp-apps/660f9784/main.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
What has caused this? More importantly, what can I do to resolve it? I've tried trashing the clickstart and recreating, but I get the same outcome each time.
Thanks
The way in which you zip the file is important.
zip -r ../myapp.zip * => WORKS FINE
zip -r myapp.zip myapp/* => DOES NOT WORK
nodejs stack expect a "main.js" script to be present in application rootdir.
You have this nodejs ClickStart working. Maybe you should compare your code with the ClickStart.

NODE_PATH is being ignored or not working

I'm trying to run my node app on a new server and am having some issues with the NODE_PATH environment variable. The app works fine on my local machine (OSX Lion) but not on the server (Redhat linux). When starting my app with node app.js from within my project directory /development/nodeproject, I get the following error :
Error: Cannot find module 'mod/core/models/Category'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at /development/nodeproject/app.js:57:5
at Object.<anonymous> (/development/nodeproject/app.js:258:1)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
mod/core/models/Category is the first require() in my app.js and looks like this: var Category = require('mod/core/models/Category'). So apparently node is not looking for modules in my project directory.
I'm not sure why though, because I made the following changes (that are working just fine on my local machine).
added export NODE_PATH=/development/nodeproject to my ~/.bash_profile
ran source ~/.bash_profile
if I run env I see NODE_PATH=/development/nodeproject listed there
in my app.js if I console log process.env.NODE_PATH I get /development/framework (should this output an array instead of a string?)
Other information that might be relevant:
I'm on node v0.6.7
I'm doing all of this as root (sudo su -)
At this point I'm not sure what else I can do. Any help would be greatly appreciated.
NODE_PATH used for modules, not for solutions files.
Try
module.paths.push("/development/nodeproject", "one/more/path");
before any require() call. And you really should use a relative require like require('./mod/core/models/Category') for files in your nodeproject directory
The functionality you are looking for was removed. Use the node_modules directory or a relative require like require('./mod/core/models/Category').
This answer has more info: NODE_PATH error with node.js while attempting to setup jsctags for vim

Resources