I m using my Mac to do nodejs development with node version v7.7.4. I wrote some code for Mongodb query with using Promise, below is part of the code:
syncInsertOne(collection,json)
{
var mongoClient = this.mongoClient;
var url=this.url;
return new Promise((resolve,reject)=>{
mongoClient.connect(url,function(err,db){
if(err){return reject(err)}
db.collection(collection).insert(json,{w:1},function(err,result){
if(err){return reject(err)}
db.close();
return resolve('done');
});
});
});
}
It run and compiled perfectly in my Mac, however when I deploy to my redhat instance in AWS EC2 with the same code, it throw below error:
return new Promise((resolve,reject)=>{
^
TypeError: promise is not a constructor
at Database.syncSortAll (/home/ec2-user/hapiService/database.js:18:12)
at Object.<anonymous> (/home/ec2-user/hapiService/database.js:195:14)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:148:9)
I m sure both my Mac and AWS instance are running the same nodejs version and the code are the same, can someone advise me the solution on this ?? I been using Promise everywhere so this is a serious issue on my project. Thanks!
via Michael Wong
No comments:
Post a Comment