DATABASE_URL undefined node.js - node.js

I config DATABASE_URL in my dashboard.
When I do in my prompt heroku config
I get:
miguel#miguel-VirtualBox:~/Escritorio/mis_proyectos/quiz$ heroku config
=== quiz-miguel2015 Config Vars
DATABASE_URL: postgres://fudidvccwppmri:Ki28zZ00ikrE43UBcKT1YnQLwb#ec2-54-83-18-87.compute-1.amazonaws.com:5432/d4fh6o7fu6cv5q
HEROKU_POSTGRESQL_GOLD_URL: postgres://fudidvccwppmri:Ki28zZ00ikrE43UBcKT1YnQLwb#ec2-54-83-18-87.compute-1.amazonaws.com:5432/d4fh6o7fu6cv5q
NODE_ENV: production
but I get this fail:
undefined
/home/miguel/Escritorio/mis_proyectos/quiz/models/models.js:5
var url = process.env.DATABASE_URL.match(/(.*)\:\/\/(.*?)\:(.*)#(.*)\:(.*)\/(.
^
TypeError: Cannot call method 'match' of undefined
at Object.<anonymous>
My file where I get the fail models.js
var path = require('path');
// Postgres DATABASE_URL = postgres://user:passwd#host:port/database
// SQLite DATABASE_URL = sqlite://:#:/
console.dir(process.env.DATABASE_URL);
var url = process.env.DATABASE_URL.match(/(.*)\:\/\/(.*?)\:(.*)#(.*)\:(.*)\/(.*)/);
I have created my file .env with the following values in the root :
DATABASE_URL=sqlite://:#:/
DATABASE_STORAGE=quiz.sqlite
Here I get the complete log:
TypeError: Cannot call method 'match' of undefined
at Object.<anonymous> (/home/miguel/Escritorio/mis_proyectos/quiz/models/models.js:5:36)
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> (/home/miguel/Escritorio/mis_proyectos/quiz/controllers/quiz_controller.js:2:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
the code is in => https://github.com/Mangulomx/Quiz

Related

Getting Error while using razorpay in file

Whenever I do
const Razorpay = require('razorpay');
There's an error coming up in node_modules/razorpay during running the server
node_modules\request-promise-core\configure\request2.js:34
var originalInit = options.request.Request.prototype.init;
^
TypeError: Cannot read property 'prototype' of undefined
at module.exports (node_modules\request-promise-core\configure\request2.js:34:48)
at Object. (node_modules\request-promise\lib\rp.js:28:1)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Module.require (internal/modules/cjs/loader.js:957:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object. (node_modules\razorpay\dist\api.js:7:15)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Module.require (internal/modules/cjs/loader.js:957:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object. (node_modules\razorpay\dist\razorpay.js:7:11)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Module.require (internal/modules/cjs/loader.js:957:19)
at require (internal/modules/cjs/helpers.js:88:18)

moongoose js Schema is not a Constructor and function error

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 :))

Error while running js file via node

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!

Error in running balloons.io app?

When I run my balloons.js (https://github.com/gravityonmars/Balloons.IO) it shows this error:
url.js:118
throw new TypeError("Parameter 'url' must be a string, not " + typeof url)
^
TypeError: Parameter 'url' must be a string, not undefined
at Url.parse (url.js:118:11)
at Object.urlParse [as parse] (url.js:112:5)
at Config (/home/user/Balloons.IO/config/index.js:56:25)
at Object.<anonymous> (/home/user/Balloons.IO/balloons.js:18:20)
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)
The above app uses Redis.

util.inherits throws TypeError: Cannot read property 'prototype' of undefined

app.js
var Website = new require( './jslib/website.js' );
./jslib/website.js
var util = require('util'),
events = require('events');
module.exports = Website;
function Website()
{
events.EventEmitter.call( this );
return this;
}
util.inherits( Website, events.EventEmiter );
Console Output
PATH_TO_APPDIR>node app.js
util.js:538
ctor.prototype = Object.create(superCtor.prototype, {
^
TypeError: Cannot read property 'prototype' of undefined
at Object.exports.inherits (util.js:538:43)
at Object.<anonymous> (PATH_TO_APPDIR\jslib\website.js:9:6)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at new require (module.js:378:17)
at Object.<anonymous> (PATH_TO_APPDIR\app.js:1:16)
at Module._compile (module.js:449:26)
This is NodeJS 8.22 on Windows 7*
You have a typo in your code.
util.inherits( Website, events.EventEmiter );
Should be
util.inherits( Website, events.EventEmitter );

Resources