Unable to start my nodejs application - javascript

Hi I am trying to start a node-js based application but it is giving me some mongodb based error and I can't seem to start my plugin.
Error:
/home/jira-Plugins/cloud/test-plugin/node_modules/mongodb/lib/server.js:110
if(host.indexOf('\/') != -1) {
^
TypeError: Cannot call method 'indexOf' of undefined
at new Server (/home/jira-Plugins/cloud/test-plugin/node_modules/mongodb/lib/server.js:110:11)
at new MongoDB (/home/jira-Plugins/cloud/test-plugin/node_modules/jugglingdb-mongodb/lib/mongodb.js:51:18)
at Object.initializeSchema [as initialize] (/home/jira-Plugins/cloud/test-plugin/node_modules/jugglingdb-mongodb/lib/mongodb.js:26:22)
at new Schema (/home/jira-Plugins/cloud/test-plugin/node_modules/jugglingdb/lib/schema.js:106:13)
at Object.<anonymous> (/home/jira-Plugins/cloud/test-plugin/app.js:56:14)
at Module._compile (module.js:456:26)
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
Here are the configurations I am currently using:
database.js
module.exports = {
url : 'mongodb://localhost/test'
};
app.js:
var mongoose = require('mongoose');
/*var methodOverride = require('method-override'); // simulate DELETE and PUT (express4)*/
var database = require('./config/database');
/*var port = process.env.PORT || 8888;*/ // set the port
mongoose.connect(database.url);
console.log('Connected to Database: ' + database.url);
var Schema = require('jugglingdb').Schema;
var schema = new Schema('mongodb');
var schema = new Schema('mongodb', {
url: 'mongodb://localhost/test',
});
I am also using jugglingdb as crossDb ORM in my application
config.json
"store": {
"adapter": "jugglingdb",
"type": "mongodb"
},
After I implemented the suggestions provided the errors has completely changed:
Unhandled error: TypeError: Cannot call
method 'indexOf' of undefined
at new Server (/home/jira-Plugins/cloud/test-plugin/node_modules/mongodb/lib/server.js:110:11)
at new MongoDB (/home/jira-Plugins/cloud/test-plugin/node_modules/jugglingdb-mongodb/lib/mongodb.js:51:18)
at Object.initializeSchema [as initialize] (/home/jira-Plugins/cloud/test-plugin/node_modules/jugglingdb-mongodb/lib/mongodb.js:26:22)
at new Schema (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/node_modules/jugglingdb/lib/schema.js:105:13)
at /home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/lib/store/jugglingdb.js:34:32
at lib$rsvp$$internal$$initializePromise (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/node_modules/rsvp/dist/rsvp.js:541:9)
at new lib$rsvp$promise$$Promise (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/node_modules/rsvp/dist/rsvp.js:757:9)
at new JugglingDB (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/lib/store/jugglingdb.js:32:18)
at module.exports (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/lib/store/jugglingdb.js:168:10)
at Function.stores.create (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/lib/store/index.js:18:10)
at stores (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/lib/store/index.js:12:17)
at EventEmitter.Addon (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/lib/index.js:31:38)
at module.exports (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/lib/index.js:204:12)
at Object.<anonymous> (/home/jira-Plugins/cloud/test-plugin/app.js:32:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
Unhandled error: TypeError: Cannot read property 'settings' of undefined
at JugglingDB.proto.isMemoryStore (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/lib/store/jugglingdb.js:78:29)
at EventEmitter.exports.shouldRegister (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/lib/internal/registration.js:45:67)
at /home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/lib/internal/registration.js:85:54
at lib$rsvp$$internal$$tryCatch (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/node_modules/rsvp/dist/rsvp.js:493:16)
at lib$rsvp$$internal$$invokeCallback (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/node_modules/rsvp/dist/rsvp.js:505:17)
at /home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/node_modules/rsvp/dist/rsvp.js:1001:13
at Object.lib$rsvp$asap$$flush [as _onImmediate] (/home/jira-Plugins/cloud/test-plugin/node_modules/atlassian-connect-express/node_modules/rsvp/dist/rsvp.js:1198:9)
at processImmediate [as _immediateCallback] (timers.js:330:15)

You didn't include any info on what is in line 56 of your app.js.
The error looks like the mongodb driver is trying to find a slash in a variable called host and fails to do so because the host is undefined.
Isn't it because you have var schema defined twice?
var schema = new Schema('mongodb');
var schema = new Schema('mongodb', {
url: 'mongodb://localhost/test',
});
Maybe remove the first one where you don't have the url.
Also, are you using both Mongoose and JugglingDB in the same program?

Related

Not able to solve "ReferenceError: Client is not defined" error

I am getting this error which I do not understand and am not able to fix.
The code is,
const fs = require('fs')
const Web3 = require('web3')
const { NonceTxMiddleware, SignedTxMiddleware, LocalAddress, CryptoUtils, HDWalletProvider } = require('#truffle/hdwallet-provider')
const client = new Client (
goerliChainId,
"https://eth-goerli.g.alchemy.com/v2/zEsvEP-zdgrdgdffgfgf64kuugnfvd6P",
"https://eth-goerli.g.alchemy.com/v2/oqB3MrwE1sdfgsdfgsdfgy5WD71Qj24n"
)
The error message is,
const client = new Client (
^
ReferenceError: Client is not defined
at Object.loadAccount (C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\utils\common.js:13:20)
at init (C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\Oracle.js:128:53)
at C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\Oracle.js:138:60
at Object.<anonymous> (C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\Oracle.js:149:3)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
I am not able to understand anything, please help.

TypeError: Missing parameter name at 14

I am building a simple server on Javascript using node.js platform. I have 2 files which are called server.js and db.js. I found a weird error while testing server.js. Below you'll find the 3 files in question. Any and all answers are greatly appreciated!
Error on node
C:\Users\Charu Nasa\Finsectrade\backend\node_modules\path-to-regexp\dist\index.js:48
throw new TypeError("Missing parameter name at " + i);
^
TypeError: Missing parameter name at 14
at lexer (C:\Users\Charu Nasa\Finsectrade\backend\node_modules\path-to-regexp\dist\index.js:48:23)
at parse (C:\Users\Charu Nasa\Finsectrade\backend\node_modules\path-to-regexp\dist\index.js:98:18)
at stringToRegexp (C:\Users\Charu Nasa\Finsectrade\backend\node_modules\path-to-regexp\dist\index.js:331:27)
at pathToRegexp (C:\Users\Charu Nasa\Finsectrade\backend\node_modules\path-to-regexp\dist\index.js:405:12)
at new Layer (C:\Users\Charu Nasa\Finsectrade\backend\node_modules\#koa\router\lib\layer.js:43:17)
at Router.register (C:\Users\Charu Nasa\Finsectrade\backend\node_modules\#koa\router\lib\router.js:570:17)
at Router.<computed> [as get] (C:\Users\Charu Nasa\Finsectrade\backend\node_modules\#koa\router\lib\router.js:200:12)
at Object.<anonymous> (C:\Users\Charu Nasa\Finsectrade\backend\server.js:11:8)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
Code file:
Server.js
const Koa = require('koa');
const Router = require('#koa/router');
const cors = require('#koa/cors');
const ethers = require('ethers');
const Paymentframework = require('../build/contracts/Paymentframework.json');
const {Payment} = require('./db.js');
const app = new Koa();
const router = new Router();
router.get('/api/getpayID/: AssetID', async (ctx) => {
ctx.body = 'goldasset';
});
app
.use(cors())
.use(router.routes())
.use(router.allowedMethods());
app.listen (4000, () =>{
console.log('Server running on port 4000');
});
db.js
const mongoose = require ('mongoose');
mongoose.connect(
'your connection string',
'mongodb+srv://abcd:<abcd1234>#finsectrade.di8n0.mongodb.net/<finsectrade >?retryWrites=true&w=majority',
{useNewUrlParser: true, useUnifiedTopology: true}
);
const paymentSchema = new mongoose.Schema({
id: String,
AssetID: String,
paid: Boolean}
);
const Payment = mongoose.model('Payment', paymentSchema);
module.exports = {
Payment
};

TypeError('Router.use() requires a middleware function but got a ' + gettype(fn)) FeathersJS

Im trying to bind a method to my /userAuthenticationInfo route, I have made some changes in my code around some of the other posts on this issue but I can't get anything to work.
Im using feathersJS's implementation of express but even using express i still get the same error. Any help would be appreciated.
app.js
const feathers = require('#feathersjs/feathers');
const express = require('#feathersjs/express');
const nano = require('cloudant-nano');
const AnnotatorService = require('./services/api/AnnotatorService');
const app = express(feathers())
.configure(express.rest())
.use(express.json())
.use(express.urlencoded({ extended: true }));
app.use('/userAuthenticationInfo', AnnotatorService.getUserAuthenticationInfo('bobby', app));
AnnotatorService.js
const nano = require('cloudant-nano');
const couchdbservice = require('#kapmug/feathers-nano/lib/index');
const host = process.env.DB_HOST || '127.0.0.1:5984';
const auth = `${process.env.DB_USERNAME || 'admin'}:${process.env.DB_PASSWORD || 'welcome'}`;
const opts = {
url: `http://${auth}#${host}`,
};
const options = {
name: 'users',
connection: nano(opts),
database: 'users',
paginate: {
default: 5,
max: 200,
},
};
var params = {
limit: 5,
skip: 0,
};
module.exports.getUserAuthenticationInfo = function (username, app) {
console.log('mission accomplished');
};
Error log
/Users/dromero/Documents/annotator-backend/node_modules/express/lib/router/index.js:458
throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
^
TypeError: Router.use() requires a middleware function but got a undefined
at Function.use (/Users/dromero/Documents/annotator-backend/node_modules/express/lib/router/index.js:458:13)
at Function.<anonymous> (/Users/dromero/Documents/annotator-backend/node_modules/express/lib/application.js:220:21)
at Array.forEach (<anonymous>)
at Function.use [as _super] (/Users/dromero/Documents/annotator-backend/node_modules/express/lib/application.js:217:7)
at Function.use (/Users/dromero/Documents/annotator-backend/node_modules/#feathersjs/express/lib/index.js:50:28)
at Function.newMethod [as use] (/Users/dromero/Documents/annotator-backend/node_modules/#feathersjs/express/node_modules/uberproto/lib/proto.js:34:20)
at Object.<anonymous> (/Users/dromero/Documents/annotator-backend/src/app.js:11:5)
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)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
In the app.use function you need to put a middleware function(pointer), whose declaration is like:
function(req, res, next){ ... }
But, by putting AnnotatorService.getUserAuthenticationInfo('bobby', app) you are actually Calling the function, which returns nothing, thus undefined.
So, it should be,
module.exports.getUserAuthenticationInfo = function (username, app) {
return function(req, res, next){
console.log('mission accomplished');
next()//or res.end() or res.send() whatever
}
};

TypeError: Cannot read property 'prototype' of undefined

I have an issue that I can't seem to resolve, mostly because I have little knowledge of why it is occurring in this particular scenario.
Here's the error :
TypeError: Cannot read property 'followers' of undefined
at Object.<anonymous> (C:\Users\username\Documents\My Lib\bot\src\bot.js:15:4)
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:393:7)
at startup (bootstrap_node.js:150:9)
at bootstrap_node.js:508:3
and here's what the code looks like :
const Twit = require('twit'),
config = require('./config'),
init = new Twit(config);
function Twitter(twitter) {
this.twitter = twitter
}
Twitter.prototype.followers = function(params) {
this.twitter.get('followers/list', params, (err, data) => {
if (!err)
data.users.forEach(user => console.log(data))
})
};
var bot = Twitter(init);
bot.followers({ screen_name: 'myscreenname'})
Haha. I'm almost certain it's a silly mistake. I just can't seem to find the source.
Any help is and will be appreciated.
You forgot the new keyword. Try this:
var bot = new Twitter(init);

TypeError: Object #<Object> has no method 'Schema'

This is the schema for our user model. But when I am running in localhost I am getting an error:
TypeError: Object # has no method 'Schema'
// app/models/user.js
// load the things we need
var neo4j = require('neo4j');
var bcrypt = require('bcrypt-nodejs');
// define the schema for our user model
var userSchema = neo4j.Schema({
facebook : {
id : String,
token : String,
email : String,
firstName : String,
lastName : String
}
});
// checking if password is valid using bcrypt
userSchema.methods.validPassword = function(password) {
return bcrypt.compareSync(password, this.local.password);
};
// this method hashes the password and sets the users password
userSchema.methods.hashPassword = function(password) {
var user = this;
// hash the password
bcrypt.hash(password, null, null, function(err, hash) {
if (err)
return next(err);
user.local.password = hash;
});
};
// create the model for users and expose it to our app
module.exports = neo4j.model('User', userSchema);
This is the error I got from the console:
C:\Users\kiit\WORKSPACE\People Discover App\app\model\user.js:7
var userSchema = neo4j.Schema({
^
TypeError: Object #<Object> has no method 'Schema'
at Object.<anonymous> (C:\Users\kiit\WORKSPACE\People Discover App\app\model\user.js:7:24)
at Module._compile (module.js:456:26)
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> (C:\Users\kiit\WORKSPACE\People Discover App\config\passport.js:8:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
I am not sure which library you are using, but there is a clue in your code as to what the issue is, namely:
"neo4j.Schema"
The capital S in Schema, if it exists in the api means that you need to be using the key word new (userSchema = new neo4j.Schema({...), unless of course the api is breaking a cardinal naming rule in javascript. It is possible that schema exist and if it does you would need to change the uppercase S to lowercase s. If neither of these options work, then your api probably does not contain a schema method or a Schema construct.

Categories