Im developing a nodejs application that needs to register to the AWS service discovery on the app start. I'm using the #aws-sdk/client-servicediscovery lib in my node application. As a reference, I am using the code from here: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-servicediscovery/index.html.
const { ServiceDiscoveryClient, CreateHttpNamespaceCommand } = require("#aws-sdk/client-servicediscovery");
const client = new ServiceDiscoveryClient({ region: "xxx" });
const params = {
"ServiceId":"xxx",
"InstanceId":"xxx",
"CreatorRequestId":new Date(new Date().toUTCString()),
"Attributes": {
AWS_INSTANCE_IPV4: "xxx.xx.xx.xx",
AWS_INSTANCE_PORT: xxx,
service: "xxx",
}
};
const command = new CreateHttpNamespaceCommand(params);
client.send(command).then(
(data) => {
console.log(data)
},
(error) => {
console.log(error)
}
);
While running the app, getting these errors.
/application/node_modules/#aws-sdk/shared-ini-file-loader/dist-cjs/slurpFile.js:5
const { readFile } = fs_1.promises;
^
TypeError: Cannot destructure property `readFile` of 'undefined' or 'null'.
at Object.<anonymous> (/application/node_modules/#aws-sdk/shared-ini-file-loader/dist-cjs/slurpFile.js:5:27)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/application/node_modules/#aws-sdk/shared-ini-file-loader/dist-cjs/loadSharedConfigFiles.js:8:21)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
I am new to the AWS SD so need some help registering my service to the service discovery. Thanks in advance!
Related
So I have a docker container (running a testing suite environment) that has stopped work on me. I'm using Mongoose 4.13.17. The problem I'm running into is every time I try to run my test cases it tries to connect to a testing db container but I get this error message.
Error: must pass in valid bson parser
at new Pool (/srv/app/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:105:13)
at Server.connect (/srv/app/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:373:17)
at Server.connect (/srv/app/node_modules/mongoose/node_modules/mongodb/lib/server.js:368:17)
at open (/srv/app/node_modules/mongoose/node_modules/mongodb/lib/db.js:229:19)
at Db.open (/srv/app/node_modules/mongoose/node_modules/mongodb/lib/db.js:252:44)
at createServer (/srv/app/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:391:6)
at /srv/app/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:512:14
at parseHandler (/srv/app/node_modules/mongoose/node_modules/mongodb/lib/url_parser.js:117:38)
at module.exports (/srv/app/node_modules/mongoose/node_modules/mongodb/lib/url_parser.js:97:5)
at connect (/srv/app/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:485:3)
at Function.MongoClient.connect (/srv/app/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:250:3)
at /srv/app/node_modules/mongoose/lib/connection.js:820:25
at Promise._execute (/srv/app/node_modules/bluebird/js/release/debuggability.js:313:9)
at Promise._resolveFromExecutor (/srv/app/node_modules/bluebird/js/release/promise.js:483:18)
at new Promise (/srv/app/node_modules/bluebird/js/release/promise.js:79:10)
at NativeConnection.Connection.openUri (/srv/app/node_modules/mongoose/lib/connection.js:819:17)
at Mongoose.connect (/srv/app/node_modules/mongoose/lib/index.js:262:17)
at new App (/srv/app/src/app.ts:34:5)
at Object.<anonymous> (/srv/app/src/app.ts:80:16)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Module.replacementCompile (/srv/app/node_modules/nyc/node_modules/append-transform/index.js:58:13)
at Module.m._compile (/srv/app/node_modules/ts-node/src/index.ts:439:23)
at module.exports (/srv/app/node_modules/nyc/node_modules/default-require-extensions/js.js:7:9)
at /srv/app/node_modules/nyc/node_modules/append-transform/index.js:62:4
at require.extensions.(anonymous function) (/srv/app/node_modules/ts-node/src/index.ts:442:12)
at Object.<anonymous> (/srv/app/node_modules/nyc/node_modules/append-transform/index.js:62:4)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/srv/app/src/server.ts:6:1)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Module.replacementCompile (/srv/app/node_modules/nyc/node_modules/append-transform/index.js:58:13)
at Module.m._compile (/srv/app/node_modules/ts-node/src/index.ts:439:23)
at module.exports (/srv/app/node_modules/nyc/node_modules/default-require-extensions/js.js:7:9)
at /srv/app/node_modules/nyc/node_modules/append-transform/index.js:62:4
at require.extensions.(anonymous function) (/srv/app/node_modules/ts-node/src/index.ts:442:12)
at Object.<anonymous> (/srv/app/node_modules/nyc/node_modules/append-transform/index.js:62:4)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/srv/app/test/unit/rest/Audio.test.ts:3:1)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Module.replacementCompile (/srv/app/node_modules/nyc/node_modules/append-transform/index.js:58:13)
at Module.m._compile (/srv/app/node_modules/ts-node/src/index.ts:439:23)
at module.exports (/srv/app/node_modules/nyc/node_modules/default-require-extensions/js.js:7:9)
at /srv/app/node_modules/nyc/node_modules/append-transform/index.js:62:4
at require.extensions.(anonymous function) (/srv/app/node_modules/ts-node/src/index.ts:442:12)
at Object.<anonymous> (/srv/app/node_modules/nyc/node_modules/append-transform/index.js:62:4)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at /srv/app/node_modules/mocha/lib/mocha.js:250:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/srv/app/node_modules/mocha/lib/mocha.js:247:14)
at Mocha.run (/srv/app/node_modules/mocha/lib/mocha.js:576:10)
at Object.<anonymous> (/srv/app/node_modules/mocha/bin/_mocha:637:18)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Module.replacementCompile (/srv/app/node_modules/nyc/node_modules/append-transform/index.js:58:13)
at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Object.<anonymous> (/srv/app/node_modules/nyc/node_modules/append-transform/index.js:62:4)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at runMain (/root/.node-spawn-wrap-45-4803909aaae7/node:68:10)
at Function.<anonymous> (/root/.node-spawn-wrap-45-4803909aaae7/node:171:5)
at Object.<anonymous> (/srv/app/node_modules/nyc/bin/wrap.js:23:4)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at /root/.node-spawn-wrap-45-4803909aaae7/node:178:8
at Object.<anonymous> (/root/.node-spawn-wrap-45-4803909aaae7/node:181:3)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:279:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)
I've looked all around for a solution but it doesn't seem like this is an extremely common problem.
This is what my class looks like:
import * as bluebird from 'bluebird';
import { Application } from 'express';
import { connect, connection, disconnect, mongo } from 'mongoose';
import * as mongoose from 'mongoose';
import 'reflect-metadata'; // this shim is required for routing-controllers
import { createExpressServer, useContainer } from 'routing-controllers';
import { Container } from 'typedi';
import { getEnv } from './Service/Env';
// middleware
import { AuthenticateTokenMiddleware } from './Middleware/AuthenticateTokenMiddleware';
import { CorsHeadersMiddleware } from './Middleware/CorsHeadersMiddleware';
import { DisableAllExceptGetMiddleware } from './Middleware/DisableAllExceptGetMiddleware';
import { ParseTokenMiddleware } from './Middleware/ParseTokenMiddleware';
// controllers
import { init } from 'ooyala-express';
import { AudioController } from './Controller/V1/AudioController';
import { MovieController } from './Controller/V1/MovieController';
import { RootController } from './Controller/V1/RootController';
import { Indexer } from './indexer';
class App {
public express: Application;
constructor() {
(<any> mongoose).Promise = bluebird;
connect(getEnv('MONGODB_URI'), { useMongoClient: true });
useContainer(Container);
Indexer.ensureIndexes();
init({
ooyala_api_host: getEnv('ooyala_api_host'),
ooyala_cdn_host: getEnv('ooyala_cdn_host'),
ooyala_rights_locker_host: getEnv('ooyala_rights_locker_host'),
ooyala_player_host: getEnv('ooyala_player_host'),
player_expiration_window: getEnv('player_expiration_window'),
});
this.express = createExpressServer({
// Disable so we don't get a nasty serialized mongoose document.
// If they fix the issue with Expose/Exclude not being respected then
// perhaps this could be set back to true
classTransformer: false,
controllers: [
RootController,
AudioController,
MovieController,
],
middlewares: [
// Order is important. Middlewares are executed in index order.
CorsHeadersMiddleware,
DisableAllExceptGetMiddleware,
ParseTokenMiddleware,
AuthenticateTokenMiddleware,
],
});
}
}
export default new App().express;
I am facing a problem with moongoose js
This is my node js code:
var mongoose=require('moongoose');
var test=mongoose.Schema({test:String})
module.exports = mongoose.model('test',test);
When I run this code, node js throws:
var test=mongoose.Schema({test:String})
^
TypeError: **mongoose.Schema is not a function**
at Object.<anonymous> (H:\TodoList\Model\TodoListModel.js:4:19)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (H:\TodoList\app.js:9:10)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
If I change this code to this format:
var mongoose=require('moongoose');
var Schema = mongoose.Schema;
var test=new Schema({test:String})
module.exports = mongoose.model('test',test);
That code throws:
TypeError: **Schema is not a constructor**
Please help me to resolve this code error.
Its require('mongoose'); you have written require('moongoose');
an o typo :))
My code is as shown below:
app.js
const app = express();
const itemsRouter = require('./routes/items.js');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use('/items', itemsRouter);
items.js
const router = require('express').router;
router.get('/itemTest', (req, res) => {
res.json({
sucess: true
});
console.log(`the parametrs are ${req.body.item_name} ${req.body.item_post}`);
});
module.exports = router;
But here somehow, I am not able to get the router working and it says that can not read property 'get' of undefined.
the error stack is as shown below:
TypeError: Cannot read property 'get' of undefined
at Object.<anonymous> (C:\Users\anand\quFlipApi\routes\items.js:5:7)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\anand\quFlipApi\app.js:33:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
There are two problems here:
It's express.Router and not express.router.
You need to create a new instance of express.Router (e.g. var router = new express.Router()) instead of trying to using the constructor directly as an instance.
I was trying to run a MQTT server in nodejs on Ubuntu 14.04 LTS
var mosca = require('mosca')
var settings = {
port: 1883,
persistence: mosca.persistence.Memory
};
var server = new mosca.Server(settings, function() {
console.log('Mosca server is up and running')
});
server.published = function(packet, client, cb) {
if (packet.topic.indexOf('echo') === 0) {
return cb();
}
var newPacket = {
topic: 'echo/' + packet.topic,
payload: packet.payload,
retain: packet.retain,
qos: packet.qos
};
console.log('newPacket', newPacket);
server.publish(newPacket, cb);
}
it is throwing following error:
/home/ubuntu/node_modules/mosca/node_modules/qlobber/lib/qlobber.js:227
for (w of st.keys())
^^ SyntaxError: Unexpected identifier
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/ubuntu/node_modules/mosca/node_modules/qlobber/index.js:3:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
Can anyone help what is that I am doing wrong?
of is a keyword in the newer ECMAScript spec, so it appears that the qlobber module used by mosca requires something newer than nodejs 0.10.x
I was trying to run my koa app.js file but I could not get it to work.
Here's my app.js
var koa = require('koa'),
monk = require('monk'),
wrap = require('co-monk');
var db = monk("mongodb url here"),
collection = db.get('mycollection'),
transactions = wrap(collection);
var app = koa();
app.use(function*(){
var res = yield transactions.find({});
console.log(res);
});
app.listen(3000);
and here's the error i got:
TypeError: Cannot read property 'name' of undefined
at makeSkinClass (/home/ric/node_modules/mongoskin/lib/utils.js:33:43)
at Object.<anonymous> (/home/ric/node_modules/mongoskin/lib/grid.js:6:35)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/ric/node_modules/mongoskin/lib/db.js:22:16)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/ric/node_modules/mongoskin/lib/mongo_client.js:5:14)
I'm still new to Koa,nodejs so I'm having a hard time figuring this out. Any help would be great!