I was workign on a Node App a few weeks ago which worked fine. I went to restart it today and its throwing this error
var mongooseUri = uriUtil.formatMongoose(mongodbUri);
^
ReferenceError: uriUtil is not defined
at Object.<anonymous> (d:\A\B\C\Web Applications\Donations1\routes\donations.js:14:19)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (d:\A\B\C\Web Applications\Donations1\app.js:9:17)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:139:18)
at node.js:999:3
It relates to this line of code that connects to mongodb
var mongodbUri = 'mongodb://AAA:BBB#ds053305.mongolab.com:12345/donations';
var mongooseUri = uriUtil.formatMongoose(mongodbUri);
You can replace this line:
var mongooseUri = uriUtil.formatMongoose(mongodbUri);
Which this line:
var mongooseUri =require('mongodb-uri').formatMongoose(mongodbUri);
Don't worry to require same module more than once. Node always require only one time, and after that use the cache for loading the module.
Related
I'm working on a Cypress project that was working fine.
But recently, it started throwing some errors. I searched for reasons as to why I was getting the errors. I found out that in my index.js file the export.module had a line to throw an error if the option algorithm was not set as below.
My question is where should I set the said algorithms and how?
Here's the git repository of the project
https://github.com/Leealp/BugsFixed2
module.exports = function(options) {
....................................................................
if (!options.algorithms) throw new Error('algorithms should be set');
var secretCallback = options.secret;
if (!isFunction(secretCallback)){
secretCallback = wrapStaticSecretInCallback(secretCallback);
}
....................
....................
}
The error is below:
C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\node_modules\express-jwt\lib\index.js:22
if (!options.algorithms) throw new Error('algorithms should be set');
^
Error: algorithms should be set
at module.exports (C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\node_modules\express-jwt\lib\index.js:22:34)
at Object.<anonymous> (C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\auth.js:20:13)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\api\users.js:3:14)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\api\index.js:8:17)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\app.js:17:13)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
PS C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)>
I want to create a simple reverse handlebars helper, but on app.js running, I have this error:
TypeError: exphbs.registerHelper is not a function
at Object.<anonymous> (C:\wamp64\www\test\login\server\example.js:7:8)
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:752:3)
Thank you very much
Nathan
Assuming the following:
const exphbs = require('exphbs');
To manually register a helper, use this:
const handlebars = exphbs.handlebars;
handlebars.registerHelper('hello', function() {
return new handlebars.SafeString('Hello!');
});
Taken from the fine manual.
I'm declaring global variable as follows:
var NODE_MODULES_PATH = process.env.NODE_PATH || 'C:/Users/../AppData/Roaming/npm/node_modules/';
global.NODE_PATH = NODE_MODULES_PATH;
but when I'm accessing it in other module e.g. flollows:
var mysql = require(NODE_PATH + 'mysql');
it gives following error:
ReferenceError: NODE_PATH is not defined
at Object.<anonymous> (z:\$app4pc\website_engine\conf\dbconnection.js:1:83)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (z:\$app4pc\website_engine\models\login_model.js:1:76)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
Process finished with exit code 1
Node.js does not automatically put things in the global scope. You should export it from your module and require it in the one that uses it. If you must set a global variable, you can use:
var GLOBAL.NODE_MODULES_PATH = ...
I know this is obvious. I just can't see it.
This is part of a node/express app..
'use strict';
var express = require('express');
var controller = require('./iresize.controller');
var router = express.Router();
router.post('/', controller.send);
module.exports = router;
Which leads to..
SyntaxError: missing ) after argument list
at (/Code/server/iresize/index.js:4:18)
i.e. var controller = require('./iresize.controller');
I don't get it. I have lots of other routes and controllers that look exactly the same. I'm not sure why this one isn't working..
Note: I have cut down the error output for clarity. There is routes.js calling it like so...
app.use('/r', require('./iresize'));
and then in iresize dir I have index.js and resize.controller files..
The full error output is as so:
node server/app.js
[Error: Module version mismatch. Expected 46, got 14.]
js-bson: Failed to load c++ bson extension, using pure JS version
SyntaxError: missing ) after argument list
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:413:25)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function._load (/Code/node_modules/pmx/lib/transaction.js:62:21)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Code/server/iresize/index.js:4:18)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function._load (/Code/node_modules/pmx/lib/transaction.js:62:21)
at Module.require (module.js:365:17)
at require (module.js:384:17)
NB: One of the Exceptions is at this file. However if I remove the app.use.. line above everything works fine.
Im getting the following error and I can't figure out through the stack trace where it's erroring.
/Users/rahulsharma/Desktop/Jobletics/node_modules/sequelize/lib/sequelize.js:298
this.importCache[path] = defineCall(this, DataTypes)
^
TypeError: object is not a function
at module.exports.Sequelize.import (/Users/ra/Desktop/Js/node_modules/sequelize/lib/sequelize.js:298:32)
at db.sequelize (/Users/ra/Desktop/Js/models/index.js:14:33)
at Array.forEach (native)
at Object.<anonymous> (/Users/ra/Desktop/Js/models/index.js:13:4)
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)
Here is the git:
https://github.com/rahul1346/jb
Any idea?
business_model.js is an empty file.