Q:Bookshelf.js:How to query by bookshelfjs? - mysql

I use the method by Bookshelfjs.org to query some datas.
But there is a bug!
This is my code.
var Defray = db.Model.extend({
tableName: 'defray',
idAttribute: 'id'
});
new Defray.query('where', 'purchaseId', '=', '2').fetch().then(function(model) {
console.log(model);
});
The database is mysql,and I want to use sql like
select * from defray where purchaseId = 2;
Bug info is
var model = this.forge();
^
TypeError: this.forge is not a function
at new Model.(anonymous function).Collection.(anonymous function) (E:\wordspace\javascript\HEKR_END\node_modules\bookshelf\lib\bookshelf.js:329:24)
at Object.<anonymous> (E:\wordspace\javascript\HEKR_END\database\model.js:30:1)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (E:\wordspace\javascript\HEKR_END\routes\index.js:6:13)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (E:\wordspace\javascript\HEKR_END\app.js:15:14)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run-script" "start"
npm ERR! node v4.2.4
npm ERR! npm v2.14.12
npm ERR! code ELIFECYCLE
npm ERR! app9d#0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app9d#0.0.0 start script 'node ./bin/www'.
npm ERR! This is most likely a problem with the app9d package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls app9d
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! E:\wordspace\javascript\HEKR_END\npm-debug.log
The sql can run at my cmd,but I can`t use bookshelf to achieve my target.
Help me,please!

Queries are a model feature not an instance one. So just change your code to query directly on the Defray model, like:
var Defray = db.Model.extend({
tableName: 'defray' // id not needed, is the default PK name
});
Defray.query('where', 'purchaseId', '=', '2').fetch().then(function(model) {
console.dir(model);
});

Related

TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider');

let provider = new ethers.providers.JsonRpcProvider(url);
^
TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')
at Object. (e:\Error\readblockchain.js:12:37)
←[90m at Module._compile (node:internal/modules/cjs/loader:1159:14)←[39m
←[90m at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:1037:32)←[39m
←[90m at Module._load (node:internal/modules/cjs/loader:878:12)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)←[39m
←[90m at node:internal/main/run_main_module:23:47←[39m
Node.js v18.12.1
PS E:\Error>See The Image-->>
Had the same problem few days ago, turned out to be problem with a beta release of ethers.js.
The fix for me was to downgrade "ethers" to version 5.4 in the package.json, then folder and lastly npm install to install ethers again.
Step 1 :in package.json
{
"dependencies": {
"ethers": "5.4" <<<<<-------------
}
}
Step 2 : Delete node_modules
Step 3 : npm install

app not deploying to heroku

I am having a problem with deploying my app on heroku. I am stuck and cannot find the answer. I have went through the heroku troubleshooting and deployment procedures. I have been trying for 3 days. I have rewritten my env file numerous times and every time I do, it doesn't work on localhost. I have MONGOD and NODEMON running. I reverted back to the original and it is working. But still will not deploy on heroku. Thanks in advance.
Here is what my env.js looks like
module.exports = {
db: process.env.MONGODB_URI || 'mongodb://localhost/sailcast',
port: process.env.PORT || 3000
}
package.json
"scripts": {
"start": "node index.js",
"postinstall": "gulp default"
},
"dependencies": {
"bcrypt": "^2.0.1",
"bluebird": "^3.5.1",
"body-parser": "^1.18.3",
"ejs": "^2.6.1",
"express": "^4.16.3",
"express-ejs-layouts": "^2.4.0",
"express-flash": "0.0.2",
"express-session": "^1.15.6",
"express-sessions": "^1.0.6",
"express-static": "^1.2.5",
"forever": "^0.15.3",
"method-override": "^2.3.10",
"mongoose": "^5.1.5",
"morgan": "^1.9.0",
"nodemon": "^1.17.5",
"passport": "^0.4.0",
"request": "^2.87.0",
"request-promise": "^4.2.2",
"yarn": "^1.7.0",
"yarn.lock": "0.0.1-security"
},
"devDependencies": {
"babel-preset-es2015": "^6.24.1",
"gulp": "^3.9.1",
"gulp-babel": "^7.0.1",
"gulp-clean-css": "^3.9.4",
"gulp-plumber": "^1.2.0",
"gulp-sass": "^4.0.1",
"gulp-uglify": "^3.0.0"
}
Here are the heroku logs. I can't figure out the error. just keep getting application error
2018-06-16T02:00:26.831441+00:00 app[web.1]: npm ERR! sailcast#1.0.0
start: `node index.js`
2018-06-16T02:00:26.831595+00:00 app[web.1]: npm ERR! Exit status 1
2018-06-16T02:00:26.831982+00:00 app[web.1]: npm ERR! Failed at the
sailcast#1.0.0 start script.
2018-06-16T02:00:26.831821+00:00 app[web.1]: npm ERR!
2018-06-16T02:00:26.832134+00:00 app[web.1]: npm ERR! This is probably
not a problem with npm. There is likely additional logging output above.
2018-06-16T02:00:26.839530+00:00 app[web.1]:
2018-06-16T02:00:26.839805+00:00 app[web.1]: npm ERR! A complete log of
this run can be found in:
2018-06-16T02:00:26.839898+00:00 app[web.1]: npm ERR!
/app/.npm/_logs/2018-06-16T02_00_26_833Z-debug.log
2018-06-16T02:00:26.898270+00:00 heroku[web.1]: Process exited with
status 1
2018-06-16T02:00:27.233835+00:00 heroku[web.1]: State changed from
starting to crashed
2018-06-16T05:23:18.892587+00:00 heroku[web.1]: State changed from
crashed to starting
2018-06-16T05:23:22.696724+00:00 heroku[web.1]: Starting process with
command `npm start`
2018-06-16T05:23:24.791728+00:00 app[web.1]:
2018-06-16T05:23:24.791759+00:00 app[web.1]: > sailcast#1.0.0 start /app
2018-06-16T05:23:24.791761+00:00 app[web.1]: > node index.js
2018-06-16T05:23:24.791762+00:00 app[web.1]:
2018-06-16T05:23:25.449215+00:00 app[web.1]: module.js:681
2018-06-16T05:23:25.449238+00:00 app[web.1]: return
process.dlopen(module, path._makeLong(filename));
2018-06-16T05:23:25.449240+00:00 app[web.1]: ^
2018-06-16T05:23:25.449242+00:00 app[web.1]:
2018-06-16T05:23:25.449244+00:00 app[web.1]: Error:
/app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2018-06-16T05:23:25.449247+00:00 app[web.1]: at Module.load
(module.js:565:32)
2018-06-16T05:23:25.449245+00:00 app[web.1]: at
Object.Module._extensions..node (module.js:681:18)
2018-06-16T05:23:25.449249+00:00 app[web.1]: at tryModuleLoad
(module.js:505:12)
2018-06-16T05:23:25.449250+00:00 app[web.1]: at Function.Module._load
(module.js:497:3)
2018-06-16T05:23:25.449252+00:00 app[web.1]: at Module.require
(module.js:596:17)
2018-06-16T05:23:25.449253+00:00 app[web.1]: at require
(internal/module.js:11:18)
2018-06-16T05:23:25.449255+00:00 app[web.1]: at Object.<anonymous>
(/app/node_modules/bcrypt/bcrypt.js:6:16)
2018-06-16T05:23:25.449257+00:00 app[web.1]: at Module._compile
(module.js:652:30)
2018-06-16T05:23:25.449258+00:00 app[web.1]: at
Object.Module._extensions..js (module.js:663:10)
2018-06-16T05:23:25.449260+00:00 app[web.1]: at Module.load
(module.js:565:32)
2018-06-16T05:23:25.449261+00:00 app[web.1]: at tryModuleLoad
(module.js:505:12)
2018-06-16T05:23:25.449263+00:00 app[web.1]: at Function.Module._load
(module.js:497:3)
2018-06-16T05:23:25.449264+00:00 app[web.1]: at Module.require
(module.js:596:17)
2018-06-16T05:23:25.449266+00:00 app[web.1]: at require
(internal/module.js:11:18)
2018-06-16T05:23:25.449267+00:00 app[web.1]: at Object.<anonymous>
(/app/models/user.js:2:16)
2018-06-16T05:23:25.449269+00:00 app[web.1]: at Module._compile
(module.js:652:30)
2018-06-16T05:23:25.449270+00:00 app[web.1]: at
Object.Module._extensions..js (module.js:663:10)
2018-06-16T05:23:25.449271+00:00 app[web.1]: at Module.load
(module.js:565:32)
2018-06-16T05:23:25.449273+00:00 app[web.1]: at tryModuleLoad
(module.js:505:12)
2018-06-16T05:23:25.449274+00:00 app[web.1]: at Function.Module._load
(module.js:497:3)
2018-06-16T05:23:25.449276+00:00 app[web.1]: at Module.require
(module.js:596:17)
2018-06-16T05:23:25.449277+00:00 app[web.1]: at require
(internal/module.js:11:18)
2018-06-16T05:23:25.457003+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-06-16T05:23:25.457360+00:00 app[web.1]: npm ERR! errno 1
2018-06-16T05:23:25.458445+00:00 app[web.1]: npm ERR! sailcast#1.0.0
start: `node index.js`
2018-06-16T05:23:25.458586+00:00 app[web.1]: npm ERR! Exit status 1
2018-06-16T05:23:25.458827+00:00 app[web.1]: npm ERR!
2018-06-16T05:23:25.458989+00:00 app[web.1]: npm ERR! Failed at the
sailcast#1.0.0 start script.
2018-06-16T05:23:25.459138+00:00 app[web.1]: npm ERR! This is probably
not a problem with npm. There is likely additional logging output above.
2018-06-16T05:23:25.493154+00:00 app[web.1]:
2018-06-16T05:23:25.493346+00:00 app[web.1]: npm ERR! A complete log of
this run can be found in:
2018-06-16T05:23:25.493475+00:00 app[web.1]: npm ERR!
/app/.npm/_logs/2018-06-16T05_23_25_460Z-debug.log
2018-06-16T05:23:25.564550+00:00 heroku[web.1]: Process exited with
status 1
2018-06-16T05:23:25.653739+00:00 heroku[web.1]: State changed from
starting to crashed
2018-06-16T10:54:29.552763+00:00 heroku[web.1]: State changed from
crashed to starting
2018-06-16T10:54:35.778827+00:00 heroku[web.1]: Starting process with
command `npm start`
2018-06-16T10:54:39.194359+00:00 app[web.1]:
2018-06-16T10:54:39.194379+00:00 app[web.1]: > sailcast#1.0.0 start /app
2018-06-16T10:54:39.194381+00:00 app[web.1]: > node index.js
2018-06-16T10:54:39.194383+00:00 app[web.1]:
2018-06-16T10:54:40.337060+00:00 app[web.1]: return
process.dlopen(module, path._makeLong(filename));
2018-06-16T10:54:40.337027+00:00 app[web.1]: module.js:681
2018-06-16T10:54:40.337063+00:00 app[web.1]: ^
2018-06-16T10:54:40.337065+00:00 app[web.1]:
2018-06-16T10:54:40.337067+00:00 app[web.1]: Error:
/app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2018-06-16T10:54:40.337069+00:00 app[web.1]: at
Object.Module._extensions..node (module.js:681:18)
2018-06-16T10:54:40.337071+00:00 app[web.1]: at Module.load
(module.js:565:32)
2018-06-16T10:54:40.337073+00:00 app[web.1]: at tryModuleLoad
(module.js:505:12)
2018-06-16T10:54:40.337074+00:00 app[web.1]: at Function.Module._load
(module.js:497:3)
2018-06-16T10:54:40.337077+00:00 app[web.1]: at require
(internal/module.js:11:18)
2018-06-16T10:54:40.337076+00:00 app[web.1]: at Module.require
(module.js:596:17)
2018-06-16T10:54:40.337079+00:00 app[web.1]: at Object.<anonymous>
(/app/node_modules/bcrypt/bcrypt.js:6:16)
2018-06-16T10:54:40.337080+00:00 app[web.1]: at Module._compile
(module.js:652:30)
2018-06-16T10:54:40.337082+00:00 app[web.1]: at
Object.Module._extensions..js (module.js:663:10)
2018-06-16T10:54:40.337084+00:00 app[web.1]: at Module.load
(module.js:565:32)
2018-06-16T10:54:40.337087+00:00 app[web.1]: at Function.Module._load
(module.js:497:3)
2018-06-16T10:54:40.337085+00:00 app[web.1]: at tryModuleLoad
(module.js:505:12)
2018-06-16T10:54:40.337088+00:00 app[web.1]: at Module.require
(module.js:596:17)
2018-06-16T10:54:40.337090+00:00 app[web.1]: at require
(internal/module.js:11:18)
2018-06-16T10:54:40.337091+00:00 app[web.1]: at Object.<anonymous>
(/app/models/user.js:2:16)
2018-06-16T10:54:40.337093+00:00 app[web.1]: at Module._compile
(module.js:652:30)
2018-06-16T10:54:40.337094+00:00 app[web.1]: at
Object.Module._extensions..js (module.js:663:10)
2018-06-16T10:54:40.337096+00:00 app[web.1]: at Module.load
(module.js:565:32)
2018-06-16T10:54:40.337097+00:00 app[web.1]: at tryModuleLoad
(module.js:505:12)
2018-06-16T10:54:40.337099+00:00 app[web.1]: at Function.Module._load
(module.js:497:3)
2018-06-16T10:54:40.337100+00:00 app[web.1]: at Module.require
(module.js:596:17)
2018-06-16T10:54:40.337102+00:00 app[web.1]: at require
(internal/module.js:11:18)
2018-06-16T10:54:40.348452+00:00 app[web.1]: npm ERR! code
ELIFECYCLE
2018-06-16T10:54:40.350021+00:00 app[web.1]: npm ERR! errno 1
2018-06-16T10:54:40.355451+00:00 app[web.1]: npm ERR! sailcast#1.0.0
start: `node index.js`
2018-06-16T10:54:40.356150+00:00 app[web.1]: npm ERR! Exit status 1
2018-06-16T10:54:40.357519+00:00 app[web.1]: npm ERR!
2018-06-16T10:54:40.358261+00:00 app[web.1]: npm ERR! Failed at the
sailcast#1.0.0 start script.
2018-06-16T10:54:40.359222+00:00 app[web.1]: npm ERR! This is probably
not a problem with npm. There is likely additional logging output above.
2018-06-16T10:54:40.384205+00:00 app[web.1]:
2018-06-16T10:54:40.384792+00:00 app[web.1]: npm ERR! A complete log of
this run can be found in:
2018-06-16T10:54:40.385145+00:00 app[web.1]: npm ERR!
/app/.npm/_logs/2018-06-16T10_54_40_366Z-debug.log
2018-06-16T10:54:40.480586+00:00 heroku[web.1]: State changed from
starting to crashed
2018-06-16T10:54:40.461008+00:00 heroku[web.1]: Process exited with
status 1
That looks fine. One thing that came up to my mind is that if your file called app.js or index.js since it is an error with npm start? Maybe you made a typo.
Another thing that came up to my mind is that, if you set up the environment database value from the heroku. Since, I cannot see your whole heroku logs, it is another possibility

getting error while doing minification of css files with gulp

Please advise i want to minify the .css files of my project with gulp so i have written the below task in my gulp.js file as shown below but still upon execution i am getting the error , please advise how to fix the below error
below is the code that I have written is
var gulp = require('gulp');
var minifyCss = require("gulp-minify-css");
gulp.task('minify-css', function () {
gulp.src('C:\\Softwares\\Spring4MVCAngularJSExample\\target\\Spring4MVCAngularJSExample\\static\\css\\*.css') // path to your file
.pipe(minifyCss())
.pipe(gulp.dest('C:\\Softwares\\Spring4MVCAngularJSExample\\target\\Spring4MVCAngularJSExample\\static\\cssoutput'));
});
below is the error i am getting upon execution
C:\Softwares\Spring4MVCAngularJSExample>gulp minify-css
module.js:471
throw err;
^
Error: Cannot find module 'gulp-minify-css'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Softwares\Spring4MVCAngularJSExample\gulpfile.js:10:13)
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)
It appears that it cannot locate the module. Have you run npm install gulp-minify-css --save-dev?
You may want to try re-installing your local packages / dependencies:
rm -rf node_modules/
npm install

IMA.js skeleton install: Cannot find module v8flags

I've tried to install hello world application with this command:
gulp app:hello
I'm getting this error message:
module.js:338
throw err;
^
Error: Cannot find module 'C:\Users\name\AppData\Roaming\npm\node_modules
\gulp\node_modules\v8flags\3.28.73.flags.json'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (C:\Users\name\AppData\Roaming\npm\node_modules
\gulp\bin\gulp.js:25:22)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
Probably you have old version of Gulp.
Try to reinstall with npm install --global gulp.

node.js fnoc module gives error -- probably something simple

I'm sure I'm doing something stupid, but I can't get node-fnoc to work. I have a directory with a simple package.json in it, I have a /config/ directory in that directory with a simple JSON file in it. And, I'm basically just trying to do what they have in their example.
var fnoc = require('fnoc');
fnoc(function(err, configs){
console.log(configs);
});
and this is what I'm getting:
fnoc(function(err, configs){
^
TypeError: object is not a function
at Object.<anonymous> (/opt/backups/readconfig.js:3:1)
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:901:3
Any ideas?
The document on github is for version 0.2.2
You need to install fnoc#0.2.2
npm install fnoc#0.2.2
Run your js
node your.js
Output:
{ package:
{ name: 'asdf',
dependencies:
{ express: '*',
jade: '*',
Version is in the changelog file:
https://github.com/jprichardson/node-fnoc/blob/master/CHANGELOG.md