I have node js project which uses mongoose and in mongoose I get the error "Unknown modifier $pushAll" which I saw whats all about it is just about versions in mongoose. I don't have any control over this file in node_modules and we have made it to work despite this error.
My problem is that it always gives UnhandledPromiseException to the console and log files which is annnoying.
My question is - How can I prevent a file,function, module or whatever exicsting in node_modules to write anything in the console? How can I catch the error given in a promise in a file I have no control over?
Related
I have been trying to connect database locally to mongodb using nodejs but there are some errors i'm facing some errors while doing that.
In my main folder there is only one connection file named as db.js and other files are package.json and node_modules. This is error I got after running the node db.js at particular location I have installed mongoose also using npm command.
and after using the command node --trace-deprecation I got the following error log.
Here's the code of db.js:-
const mongoose=require('mongoose');
mongoose.connect('mongodb://localhost:27017').then(()=>{
console.log(`conncn established!!\n`);
}).catch((err)=>{
console.log('no connection',err);
})
// module.exports=mongoose;
// "mongodb://localhost:27017/Blogs_db -->it is the connection string for Blogs_db tried to but this //string also but it is not working
I have checked whether my server is running or not and tried to make the new folder and to follow the process again but it still shows the connection error
Go the answer and it is simple just to replace the local host in the connection string with 0.0.0.0 and it worked[Heres the output after replacing the localhost in above code with 0.0.0.0]
There is something wrong with the way I understand how to use classes in a Javascript module and export them, or some bad assumption I made about how nodejs works. Please help me understand this better. I wanted to write a module that exposed an object that will "store things safely." I have a file ("safestore.js") with this in it:
class Safestore {
constructor() {
console.log("SUCCESS!");
}
... // I defined other methods here...
}
exports.safestore = Safestore; // I tried this with `new Safestore` and `new Safestore()` too.
I run nodejs on my command line and then:
> ss = require('./safestore');
{ safestore: [Function] }
> s = ss.safestore('pwd','./encFile.enc');
ReferenceError: Safestore is not defined...
Why is it telling me that Safestore is not defined while executing the safestore function which is defined in the same file where Safestore is, actually defined?
The question does not contain enough information, although there is a clue. node and nodejs are two different pieces of software, and I was using the wrong one. I also didn't specify what version of nodejs I ran from my command line. When I ran it with node (instead of nodejs) I got errors that made sense and I was able to fix them.
Thanks to #Ethicist for listing the version of Node he used, as this got me to double check all those things.
I just need to remember that node and nodejs each do different things. Further research shows me that nodejs is a symlink to version 8.10.0 of node.js, and node is a symlink to the version that I set with nvm. I solved the problem permanently for myself with sudo rm /user/bin/nodejs and I'll remember, if I ever see an error that says nodejs doesn't exist, that it wants the old version of node.js.
I have a challenge using the Node's process.on function in the Vue CLI project's main.js file.
I have the following code in the file.
process.on("unhandledRejection", function(reason, promise){
console.log("Unhandled", reason, promise); // log all your errors, "unsuppressing" them.
throw reason; // optional, in case you want to treat these as errors
});
The project builds but when the app is opened on the browser, I get an error:
Uncaught TypeError: process.on is not a function
How do I configure the project so that I can use the Node's process?
Am I not understanding NodeJS in this context?
Is there something I am missing?
Any assistance is appreciated thanks.
I'm still new to node.js and mongodb. Now I'm trying to solve this problem.
I have instructions to run my server without any problems, I follow them and yes my server works. But when I switched the server off then run it again I face this bug:
[vagrant#localhost ~]$ node /opt/inapsrv/app/app.js
app-api listening at http://0.0.0.0:7000
/opt/inapsrv/node_modules/fileupload/lib/modules/file.js:23
throw error
^
Error: ENOENT, mkdir 'data/imagex/'
And here is the line of the directory above taken from app.js file:
var imagePath = 'data/imagex/';
I tried to:
make vagrant and mongo users as super users and they have the root permissions.
to run "sudo node /opt/inapsrv/app/app.js"
run "forever /opt/inapsrv/app/app.js"
and it didn't work.
I don't know why it successfully ran the first time, and then it didn't!
Any help?
I suspect you're using node module fileupload for the upload job. The source code fragment in fileupload that throws your error can be found here.
The problem with the code used in fileupload module is that it does not create recursive directories since fs.mkdir is used. To fix your issue try to create the upload directory or at least data upfront. You could do this by a npm script, in app.js using the mkdirp or simply by a shell script.
The problem described is not related to mongodb or mongoose.
I've been using Node.js + Express + Jade for a long time.
Since upgrading to node 0.8.12, the render( ... ) command just times out on my production server.
In this example, "1" is printed to the log, but "2" is not, and the page times out. Of course, I properly have a file called views/test.jade. And, again, this works fine on my test server with the same code...
console.log('1');
res.render('test');
console.log('2');
So I downgraded Node.js back to 0.6.18 (what I was using before) and the code works fine again. But I need the newer node version... the one major difference that I can think of is that 0.6.18 was installed on CentOS via YUM, but I had to make v0.8.12 myself because I could not find an appropriate package.
Here's what I've tried:
Upgrading express (#3.0.0rc5) and jade (#0.26.3)
Using a callback in the render() func (it is never called)
Explicitly setting the views/ directory via app.set('views', absolute_path);
Using an invalid template name intentionally in attempts to get an error. Still, nothing (no callback fired, no execution)
Crying
Ideas?
Make sure that jade is correctly installed. If the render call is timing out, it most likely means that an error is being thrown that you are not handling. You can check for errors being thrown like this:
try {
res.render('test');
}
catch (e) {
console.log(e);
}
Since render doesn't depend on much, I'd guess that the jade module isn't installed correctly. Make sure that you see jade in your node_modules\express folder. If you don't, try re-installing:
npm install express