I work primarily with asp.net/C#/SQL applications, but have been handed a node.js/MongoDB application that I need to support. The client lost the original developers and I'm trying to figure fix an issue they're having. Currently I'm trying to find a "process" that runs and checks/makes updates to the database every 60 seconds. I've found the script that does the checks/updates, but I don't know where it gets called from or how the variables passed to it are getting populated. Can someone help me find how this "process" works?
So there's a script called eoaBatch.js that reads and writes to the database. It appears to have an object called api passed to it. It's that api object that I need to know how it is populated; that seems to be the current problem. Here's part of the code for eoaBatch.js:
exports.task = {
name: 'eoaBatch',
description: 'End of Batch Processor',
queue: 'eoa',
plugins: [],
pluginOptions: [],
frequency: 60 * 1000, // 1 minute
run: function (api, params, next) {
var Auction = mongoose.model('auctions');
var eoaBatch = mongoose.model('eoaBatches');
var eoaProperty = mongoose.model('eoaProperties');
var eoaBid = mongoose.model('eoaBids');
var Property = mongoose.model('properties');
var SubAccounts = mongoose.model('subaccounts');
var eoaAuction = mongoose.model('eoaAuctions');
async.eachSeries(
api.batches,
function forEachBatch(batchInfo, callback) {
How do I find out what calls/starts/runs this script?
How can I find what is in the api object?
Edit:
Here's package.json. I replaced the project name with PROJ and removed any other identifying information:
{
"name": "PROJ-api",
"version": "1.8.0",
"description": "PROJ",
"keywords": [
"PROJ"
],
"homepage": "https://www.PROJ.com",
"bugs": {
"email": ""
},
"license": "UNLICENSED",
"author": "",
"contributors": [
],
"repository": "/PROJ-api",
"scripts": {
"start": "node ./node_modules/.bin/actionhero start",
"ci-test": "istanbul cover _mocha > test.tap && istanbul report clover",
"ci-lint": "eslint -f checkstyle . > checkstyle-result.xml; true"
},
"dependencies": {
"accounting": "^0.4.1",
"actionhero": "^12.3.0",
"async": "^1.5.0",
"dateformat": "^1.0.12",
"grunt": "^0.4.5",
"kerberos": "0.0.17",
"lodash": "^3.10.1",
"mandrill-api": "^1.0.45",
"mongoose": "^4.2.9",
"mongoose-datatable": "^1.0.6",
"node-uuid": "^1.4.7",
"redis": "^2.4.2",
"tv4": "^1.2.7",
"validator": "^4.3.0",
"ws": "^0.8.1"
},
"devDependencies": {
"babel-eslint": "^5.0.0-beta4",
"babel-preset-airbnb": "^1.0.1",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^1.0.2",
"eslint-plugin-react": "^3.11.2",
"istanbul": "^0.4.1",
"mocha": "^2.3.4",
"should": "latest"
},
"engines": {
"node": ">=4.2.0"
},
"os": [
"darwin",
"linux"
],
"private": true
}
This is a background job for a job queue implemented for ActionHero
Your file creates tasks.
From the docs:
api: The actionhero api object
params: An array of parameters that
the task was enqueued with. This is whatever was passed as the second
argument to api.tasks.enqueue
next: A callback to call when the task
is done. This callback is of the type function(error, result).
Passing an error object will cause the job to be marked as a failure.
The result is currently not captured anywhere.
Related
I am having an issue with my ExpressJS app using sequelize. When I run the app, I get this message:
node:internal/modules/cjs/loader:488
throw e;
^
Error: Cannot find module
'C:\node_projects\my_app\node_modules\sequelize\dist\lib\table-hints'
This issue started happening after I edited one of my app's routes, which has nothing to do with app initialization. I cannot share code, because it seems to be a problem within sequelize itself.
My package.json looks like this:
{
"name": "my_app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon index.js",
"client": "npm run start --prefix client",
"dexy": "concurrently \"npm start\" \"npm run client\" ",
"test": "node_modules/.bin/mocha tests.js --timeout 10000"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"bluebird": "^3.7.2",
"body-parser": "^1.19.1",
"cookie-session": "^2.0.0",
"ejs": "^3.1.6",
"express": "^4.17.2",
"express-validation": "^3.0.8",
"express-validator": "^6.14.0",
"helmet": "^4.6.0",
"joi": "^17.5.0",
"mailgun-js": "^0.22.0",
"moment": "^2.29.1",
"morgan": "^1.10.0",
"passport": "^0.5.2",
"passport-facebook": "^3.0.0",
"passport-google-oauth20": "^2.0.0",
"passport-local": "^1.0.0",
"pg": "^8.7.1",
"request": "^2.88.2",
"request-promise": "^4.2.6",
"sequelize": "^6.12.2",
"tedious": "^14.0.0",
"uuid": "^8.3.2"
}
}
The code I use to init my db is like this:
function dbInit(app){
const Sequelize = require('sequelize');
const keys = require('../config/keys');
const sqlCon = new Sequelize(keys.dbName,keys.dbUser, keys.dbPassword,
{dialect:'postgresql',
host:keys.dbHost,
pool:20,
logging:false
});
app.locals.connection = sqlCon;
//wire up model definitions
const User = require('../models/User')(sqlCon,sequelize);
const PasswordResetRequest = require('../models/PasswordResetRequest')(sqlCon,sequelize);
const CertType =require('../models/CertType')(sqlCon,sequelize);
const Role =require('../models/Role')(sqlCon,sequelize);
app.locals.User = User;
app.locals.PasswordResetRequest = PasswordResetRequest;
app.locals.CertType = CertType;
app.locals.Role = Role;
//setup relationships between tables
require('../models/relationships')(app);
sqlCon.sync().then(()=>{
return sqlCon.authenticate()
})
.catch((err)=>{
console.log('Successfully NOT connected to DB!');
console.log(err);
});
return sqlCon;
}
Can anyone shed any light on why this error happens? Thanks! I already downgraded sequelize from version 7-aplha2.
I have a console bug. please help
Mongo is not defined - problem while loading data from the server
C:\Users\Robert\Desktop\FINISH\node_modules\mongodb\lib\utils.js:123
process.nextTick(function() { throw err; });
ReferenceError: mongo is not defined
at C:\Users\Robert\Desktop\FINISH\routes\info.js:38:70
at C:\Users\Robert\Desktop\FINISH\node_modules\async\lib\async.js:122:13
at _each (C:\Users\Robert\Desktop\FINISH\node_modules\async\lib\async.js:46:13)
at Object.async.each (C:\Users\Robert\Desktop\FINISH\node_modules\async\lib\async.js:121:9)
at C:\Users\Robert\Desktop\FINISH\routes\info.js:34:31
at handleCallback (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb\lib\utils.js:120:56)
at C:\Users\Robert\Desktop\FINISH\node_modules\mongodb\lib\cursor.js:861:16
at handleCallback (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb-core\lib\cursor.js:171:5)
at setCursorDeadAndNotified (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb-core\lib\cursor.js:505:3)
at nextFunction (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb-core\lib\cursor.js:660:7)
package.json:
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"async": "^0.9.0",
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.10.2",
"bson": "^4.2.2",
"client-sessions": "^0.7.0",
"express": "^4.11.1",
"express-handlebars": "^2.0.1",
"mongodb": "^2.2.33"
}
}
Line 38 of info.js references mongo: mongo.ObjectID..., but mongo does not exist in that file. You need to add const mongo = require('mongodb') to the top of the file along with your require of the async module. And for future reference, you can edit posts on StackOverflow rather than replying with detail as an answer.
I cannot obtain a response from the getStateByPartialCompositeKey method. I can use putState and getState just fine, but cannot use getStateByPartialCompositeKey. I'm using NodeJS fabric-contract-api version of Fabric's chaincode.
For the development, I used this commercial-paper example. This example uses the test-network environment, which is working just fine.
This implementation offers some ledger API utility classes that I'm using also to interact with the ledger. It has two classes, state.js and stateList.js I added a method to stateliest called getAllStatesFromPartialCompositeKey to try and use getStateByPartialCompositeKey method.
Package.json
{
"name": "informed-consent-form-contract",
"version": "0.0.5",
"description": "Papernet Contract",
"main": "index.js",
"engines": {
"node": ">=8",
"npm": ">=5"
},
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "nyc mocha test --recursive",
"start": "fabric-chaincode-node start",
"mocha": "mocha test --recursive"
},
"engineStrict": true,
"author": "hyperledger",
"license": "Apache-2.0",
"dependencies": {
"axios": "^0.19.2",
"fabric-contract-api": "^2.0.0",
"fabric-shim": "^2.0.0",
"node-fetch": "^2.6.0",
"nodemon": "^2.0.2"
},
"devDependencies": {
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"eslint": "^4.19.1",
"mocha": "^5.2.0",
"nyc": "^12.0.2",
"sinon": "^6.0.0",
"sinon-chai": "^3.2.0"
},
"nyc": {
"exclude": [
"coverage/**",
"test/**"
],
"reporter": [
"text-summary",
"html"
],
"all": true,
"check-coverage": true,
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100
}
}
Contract.js snippet:
/**
*
* #param {*} ctx
* #param {*} partialKey - Piece of key to serch
*/
async getAllStates(ctx, partialKey) {
let result = await ctx.informedConsentFormStateList.getStatesFromPartialCompositeKey(partialKey);
console.log('================ Result inside getAllStates method ================');
console.log(result);
return result;
} // fin func
Insinde informedConsentFormStateList.js:
```
async getStatesFromPartialCompositeKey(partialKey) {
return this.getAllStatesFromPartialCompositeKey(partialKey);
}
```
Inside the modified stateList.js:
/**
* #function getAllStatesFromPartialCompositeKey
*/
async getAllStatesFromPartialCompositeKey(partialArgument) {
console.log('================ Called from beginning of getAllStatesFromPartialCompositeKey ================');
console.log('================ name => ' + this.name);
let key = this.ctx.stub.createCompositeKey(this.name, [partialArgument]);
console.log('================ created partial key .....');
console.log(partialArgument);
console.log(key);
let response = await this.ctx.stub.getStateByPartialCompositeKey(this.name, [key]); //.toString('utf8')
console.log('================ response below ================');
console.log(response);
let results = await this.getAllResults(response);
return results;
} // fin getAllStatesFromPartialCompositeKey
Here is how I invoke it:
/home/ubilab/fabric2/fabric-samples/test-network$ peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name informed_consent_9 --tls true --cafile $ORDERER_CA --peerAddresses localhost:7051 --tlsRootCertFiles $ORG1_CA -c '{"Args":["csacmpcc:getAllStates","P03"]}'
Response:
chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 payload:"[]"
Chaincode container logs:
================ Called from beginning of getAllStatesFromPartialCompositeKey ================
================ name => org.csa.informedconsentformstatelist
================ created partial key .....
P03
org.csa.informedconsentformstatelistP03
================ Result inside getAllStates method ================
[]
Couchdb Stored state:
{
"id": "\u0000org.csa.informedconsentformstatelist\u0000\"P03\"\u0000\"R68\"\u0000",
"key": "\u0000org.csa.informedconsentformstatelist\u0000\"P03\"\u0000\"R68\"\u0000",
"value": {
"rev": "1-74db76a10ad8251ce2ba49ad58710ad8"
},
"doc": {
"_id": "\u0000org.csa.informedconsentformstatelist\u0000\"P03\"\u0000\"R68\"\u0000",
"_rev": "1-74db76a10ad8251ce2ba49ad58710ad8",
"class": "org.csa.informedconsentform",
"consentStatus": "1",
"currentState": null,
"key": "\"P03\":\"R68\"",
"patientID": "P03",
"reserachID": "R68",
"sensors": "{numberOfSensors:1,sensors:[{sensorID:s01,name:SPO2,startDate:5/12/2020,endDate:5/12/2021}]}",
"~version": "CgMBZQA="
}
}
If you need more information to be able to help me please do not hesitate to ask :). Thanks!
Given you are querying with a single attribute, try using the partialKey variable directly instead of building a composite key.
let response = await this.ctx.stub.getStateByPartialCompositeKey(this.name, [partialKey]);
API docs
A better way to get a response would be to use an iterator :
let allResults = [];
let res = { done: false, value: null };
let jsonRes = {};
res= await ctx.stub.getStateByPartialCompositeKey(this.name, [partialKey]);
while (!res.done) {
jsonRes.Key = res.value.key;
try {
jsonRes.Record = JSON.parse(res.value.value.toString('utf8'));
allResults.push(jsonRes);
res = await iterator.next();
}
catch (err) {
console.log(err);
return {}
}
}
await iterator.close();
return allResults;
I have a folder containing some .js files, written in pre-ES2015 JavaScript, along with a corresponding gulpfile.js, to compile my code. Now, I'm trying to add babel so that I can start writing code in in ES6.
After installing the npm packages I thought I would need and then running gulp, it finishing compiling without any issues, but my ES6 code isn't transpiled (i.e., const doesn't become var, arrow functions still present in the compiled code).
What I've tried:
In gulpfile.js, I've tried a few different values for the presets option -- ['es2015'], ['babel-preset-es2015'], and ['babel-preset-env'].
But one of 2 things happens: 1. gulp finishes without errors, 2. the message Couldn't find preset "es2015" relative to directory... is returned.
Could this be a versioning issue? Or perhaps I haven't configured my babel-preset correctly?
(I've included below my package.json, as well as the relevant part of my gulpfile.js)
package.json:
{
"name": "SA",
"version": "2.0.0",
"description": "my SA code",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-eslint": "^7.2.3",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"del": "^2.2.2",
"eslint": "^3.19.0",
"gulp": "^4.0.2",
"gulp-babel": "^7.0.1",
"gulp-concat": "^2.6.1",
"gulp-jscs": "^4.1.0",
"gulp-jscs-stylish": "^1.4.0",
"gulp-jshint": "^2.1.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^3.0.2",
"jshint": "^2.9.5",
"jshint-stylish": "^2.2.1"
},
"main": "SA",
"dependencies": {
"#babel/preset-env": "^7.6.3",
"lodash": "^4.17.15"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"repository": {
"type": "git",
"url": "[github URL]"
},
"keywords": []
}
gulpfile.js (including relevant parts):
var babel = require('gulp-babel'),
concat = require('gulp-concat'),
del = require('del'),
gulp = require('gulp'),
jscs = require('gulp-jscs'),
jshint = require('gulp-jshint'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify');
function createBuildTask(destination) {
var sourceArray = [
destination + '/config/mobileCheck.js',
destination + '/config/account.js',
'common/api.js',
destination + '/config/utilityFunctions.js',
destination + '/config/runFirst.js',
destination + '/' + destination + '-main.js'
];
return function () {
return gulp.src(sourceArray, {'allowEmpty': true})
.pipe(concat(destination + '-built-main.js'))
.pipe(gulp.dest(destination + '/dist'))
.pipe(babel({
'presets': ['babel-preset-env']
}))
.pipe(uglify())
.pipe(rename({
'extname': '.min.js'
}))
.pipe(gulp.dest(destination + '/dist'));
};
}
Im trying to make a Desktop App with Electron and React.
Im allerdings getting startet and the most components are working, but in my React component I need to make a new Funktion like:
add = () => {
//this.setState({active: !this.state.active})
}
But after adding this 3 (2) Lines i get the error:
app/app.js: Unexpected token (17:11) while parsing file: .../app/app.js
this is my package.json so far:
{
"name": "rac",
"productName": "rac-desktop",
"version": "1.0.0",
"description": "desktop",
"main": "main.js",
"scripts": {
"start": "electron main.js",
"watch": "watchify app/app.js -t babelify -o public/js/bundle.js -- debug --verbose"
},
"author": "timo",
"license": "MIT",
"dependencies": {
"axios": "^0.16.2",
"babel-preset-es2015": "6.24.1",
"babel-preset-react": "6.24.1",
"babelify": "7.3.0",
"classnames": "2.2.5",
"electron-prebuilt": "^1.4.13",
"electron-reload": "^1.2.2",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"semantic-ui-react": "^0.75.1"
} }
The Repo
That is not valid syntax for a class function in Javascript.
A class has functions like so:
class Test {
constructor() {
// do stuff
}
// basic function
doSomething() {
this.test++;
}
}
So in your case you just need to make add use the correct syntax for a function in a class
add() {
this.setState({active: !this.state.active});
}
The syntax you have used is coming in the future as part of the Class Fields Proposal