Error while deploying to Google App Engine - node.js

I am trying to deploy an application to Google App Engine. Its a Node.js application with MySQL Backend. I am using Sequelize ORM. Both the Cloud SQL Instance and the App Engine are in the same project. When I try to deploy and start the application I am getting the following error.
Updating service [default] (this may take several minutes)...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
> teachhub#1.0.0 start /app
> node server
/app/node_modules/sequelize/lib/sequelize.js:236
throw new Error('The dialect ' + this.getDialect() + ' is not supported. Supported dialects: mssql, mysql, postgres, and sqlite.');
^
Error: The dialect my-nodejs-codelab-1217-190421 is not supported. Supported dialects: mssql, mysql, postgres, and sqlite.
at new Sequelize (/app/node_modules/sequelize/lib/sequelize.js:236:15)
at Object.<anonymous> (/app/models/index.js:13:18)
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> (/app/routes/apiRoutes.js:1:72)
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> (/app/server.js:3:14)
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)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! teachhub#1.0.0 start: `node server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the teachhub#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-07-08T15_03_28_369Z-debug.log
Given below is my models/index.js...
"use strict";
var fs = require("fs");
var path = require("path");
var Sequelize = require("sequelize");
var basename = path.basename(module.filename);
var env = process.env.NODE_ENV || "development";
let keys = require(__dirname + "/../config/config.js");
keys = keys.dbConfig[env];
var db = {};
if(process.env.INSTANCE_CONNECTION_NAME){
var sequelize = new Sequelize(process.env.INSTANCE_CONNECTION_NAME, {dialect:"mysql"});
} else if (process.env.JAWSDB_URL) {
var sequelize = new Sequelize(process.env.JAWSDB_URL);
} else if (keys.use_env_variable) {
var sequelize = new Sequelize(process.env[keys.use_env_variable], keys);
} else {
var sequelize = new Sequelize(
keys.database,
keys.username,
keys.password,
keys
);
}
Can someone please help?

It seems that it is missing a definition to the sequelize dialect. In your case ‘key.dialect’, assuming that you have defined the dialect in your config file. The dialect defines the kind of database used on your project as you can confirm in the following documentation: http://docs.sequelizejs.com/manual/installation/usage.html
In the Documentation:
const sequelize = new Sequelize({
database: 'db_name',
username: 'username',
password: null,
dialect: 'mysql'
});
In your code:
enter codvar sequelize = new Sequelize(
Keys.database,
keys.username,
keys.password,
keys.dialect
);

Related

node.js module not found in subfolder

I am building a basic web scraper using node, express, and puppeteer, and when I try to run node index.js. I get this error
alexskreen#Alexs-MacBook-Air WOD-Scraper2 % node server/index.js
internal/modules/cjs/loader.js:960
throw err;
^
Error: Cannot find module './server/scrapers'
Require stack:
- /Users/alexskreen/Desktop/WOD-Scraper2/server/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/Users/alexskreen/Desktop/WOD-Scraper2/server/index.js:8:18)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/alexskreen/Desktop/WOD-Scraper2/server/index.js' ]
}
Before adding my require statements everything is working:
const express = require("express");
const app = express();
const port = 3000;
const bodyParser = require("body-parser");
const scrapers = require('./server/scrapers');
const db = require('./server/db');
If module is in your subfolder you should use,
const something = require("./subfolder/module");
If it is not a subfolder module then make sure it is installed in node_modules.

Error: Cannot find module 'camelcase'

I'm trying to run a gulp based application.
On Ubuntu, everything is working, but on Debian server not.
Ubuntu: npm: 5.3.0, nodejs: v8.2.1, bower#1.8.0, gulp-cli#1.4.0, npm#5.3.0
Debian: npm: 5.3.0, nodejs: v8.2.1, bower#1.8.0, gulp-cli#1.4.0, npm#5.3.0
Gulpfile:
'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass');
gulp.task('scss2css', function () {
gulp.src(['./web/scss/style.scss'])
.pipe(sass({outputStyle: 'compressed'}))
.pipe(gulp.dest('./web/css/'));
});
gulp.task('scss2css:watch', function () {
gulp.watch('./scss/**/*.scss', ['scss2css']);
});
gulp.task('default', function () {
gulp.start('scss2css');
});
When I type "gulp", I receive message like below:
module.js:487
throw err;
^
Error: Cannot find module 'camelcase'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/gulp-cli/node_modules/yargs/lib/parser.js:3:17)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
I just removed nodejs package and directories:
/usr/lib/node_modules/
/usr/local/lib/node_modules/

mongoose.connect not invoking callback after connection to mongodb

I'm trying to make a connection to MongoDB using Mongoose. But it does neither throw a error nor connect to the database. Following is my code.
const express = require('express');
const app = express();
const port = process.env.PORT || 8080;
const mongoose = require('mongoose');
console.log('Hi, there!!');
mongoose.connect('mongodb://localhost:27017/db_name', (err) => {
console.log('Callback called');
if(err) throw err;
console.log('Connected to database');
})
In the above code none of the console.log inside the callback do happen. But any place outside the mongoose.connect do work like console.log('Hi, there!!')
Versions Used
express: 4.0.0
mongoose: 3.8.40
node: 7.7.3
mongodb: 3.4.0
Using mongoose: 3.8.40 I got this in the console :
{ Error: Cannot find module '../build/Release/bson'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/kevin/nemeacreation/sites/test/stackoverflow/node_modules/bson/ext/index.js:15:10)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3) code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
Hi, there!!
upgrading to "mongoose": "~4.4" fixed it for me. I got the answer here : https://stackoverflow.com/a/35516644/2829540
For info the latest release of mongoose is 4.10.4

Lab returns error no method 'experiment'

I am writing the test code for a function that will check for the existence of a username in twitter. I am using the Hapi framework and Lab for testing.
When I run npm test I get the following error:
> NameGen#0.0.0 test /Users/mario/projects/NameGen
> ./node_modules/lab/bin/lab -c
/Users/mario/projects/NameGen/test/test.js:5
Lab.experiment( "Test Username Existence", function() {
^
TypeError: Object #<Object> has no method 'experiment'
at Object.<anonymous> (/Users/mario/projects/NameGen/test/test.js:5:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js [as origLoader] (module.js:474:10)
at Object.require.extensions..js (/Users/mario/projects/NameGen/node_modules/lab/lib/coverage.js:32:26)
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 /Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:85:23
at Array.forEach (native)
at Object.internals.traverse (/Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:81:19)
at Object.exports.run (/Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:30:29)
at Object.<anonymous> (/Users/mario/projects/NameGen/node_modules/lab/bin/lab:3:23)
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:906:3
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
My test code is:
var Lab = require("lab");
var server = require('../'); // require index.js
var request = require('request');
Lab.experiment( "Test Username Existence", function() {
// tests
Lab.test( "Test username exists", function(done){
var options = {
url: 'http://twitter.com/BarackObama'
};
request(options, function(error, response, body){
Lab.expect(response.statusCode).to.equal(200);
});
done();
});
Lab.test("Test username does not exists", function(done){
var options = {
url: 'http://twitter.com/jhkhksdhkjahsdfkjhasdf'
};
request(options, function(error, response, body){
Lab.expect(response.statusCode).to.equal(404);
});
done();
});
});
I have the latest version of node installed and all the necessary dependencies in my package.json file. What could be causing this error?
As #Jordonias had stated. However, when I used his example, it still did not work.
I had to change the 2nd line to:
lab = exports.lab = Lab.script()
Per the Lab docs: Test files must require the lab module, and export a test script
test.js
var Lab = require('lab');
var lab = module.exports = Lab.script();
lab.experiment( "Test Username Existence", function() {
lab.test( "Test username exists", function(done){
});
});

karma start throwing useragent error

I generated an app using yeoman by doing this in a folder called sw-front:
yo angular
I installed karma like this
npm install -g karma
npm install -g karma-cli
grunt serve works fine.
karma -v throws the same error:
mm-mac-2186:sw-front pkatepalli$ karma start
module.js:340
throw err;
^
Error: Cannot find module 'useragent'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/pkatepalli/Desktop/hands-on-angular/sw-front/node_modules/karma/lib/helper.js:4:17)
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)
module.js:
var Module = function() {
var providers = [];
this.factory = function(name, factory) {
providers.push([name, 'factory', factory]);
return this;
};
this.value = function(name, value) {
providers.push([name, 'value', value]);
return this;
};
this.type = function(name, type) {
providers.push([name, 'type', type]);
return this;
};
this.forEach = function(iterator) {
providers.forEach(iterator);
};
};
module.exports = Module;
mm-mac-2186:sw-front pkatepalli$ node -v
v0.10.28
mm-mac-2186:sw-front pkatepalli$ npm -v
1.4.9
Try
npm cache clean
And removing the node_modules directory, if it exists, where you are running the commands form.
Then rebuild/reinstall

Resources