I'm getting the following error if I run any api end point where db operation is involved in sails.js (v 1.4.0). I'm using sails-mysql (v 1.0.1).
For your information, it is producing this error in aws ec2 ubuntu 18. My node version 13/14.
I'm not getting any error in my development environment.
error: Sending 500 ("Server Error") response:
AdapterError: Unexpected error from database adapter: `select` failed ("badConnection"). A connection either could not be obtained or there was an error using the connection.
Additional data:
{
error: Error: getaddrinfo EAI_AGAIN abmaster
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)
--------------------
at Protocol._enqueue (/var/www/html/api/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Protocol.handshake (/var/www/html/api/node_modules/mysql/lib/protocol/Protocol.js:52:23)
at PoolConnection.connect (/var/www/html/api/node_modules/mysql/lib/Connection.js:130:18)
at Pool.getConnection (/var/www/html/api/node_modules/mysql/lib/Pool.js:48:16)
at Object.getConnection (/var/www/html/api/node_modules/machinepack-mysql/lib/get-connection.js:78:25)
at wrapper (/var/www/html/api/node_modules/#sailshq/lodash/lib/index.js:3282:19)
at Deferred.parley.retry [as _handleExec] (/var/www/html/api/node_modules/machine/lib/private/help-build-machine.js:1076:19)
at Deferred.exec (/var/www/html/api/node_modules/parley/lib/private/Deferred.js:286:10)
at Deferred.switch (/var/www/html/api/node_modules/machine/lib/private/help-build-machine.js:1469:16)
at spawnConnection (/var/www/html/api/node_modules/sails-mysql/helpers/private/connection/spawn-connection.js:29:10)
at Object.spawnOrLeaseConnection (/var/www/html/api/node_modules/sails-mysql/helpers/private/connection/spawn-or-lease-connection.js:23:3)
at Object.select (/var/www/html/api/node_modules/sails-mysql/helpers/select.js:122:24)
at wrapper (/var/www/html/api/node_modules/#sailshq/lodash/lib/index.js:3282:19)
at Deferred.parley.retry [as _handleExec] (/var/www/html/api/node_modules/machine/lib/private/help-build-machine.js:1076:19)
at Deferred.exec (/var/www/html/api/node_modules/parley/lib/private/Deferred.js:286:10)
at Deferred.switch (/var/www/html/api/node_modules/machine/lib/private/help-build-machine.js:1469:16)
at Object.find (/var/www/html/api/node_modules/sails-mysql/lib/adapter.js:185:16)
at _getPopulatedRecords (/var/www/html/api/node_modules/waterline/lib/waterline/utils/query/help-find.js:145:21)
at helpFind (/var/www/html/api/node_modules/waterline/lib/waterline/utils/query/help-find.js:582:6)
at _afterPotentiallyRunningBeforeLC (/var/www/html/api/node_modules/waterline/lib/waterline/methods/find-one.js:265:9)
at _maybeRunBeforeLC (/var/www/html/api/node_modules/waterline/lib/waterline/methods/find-one.js:239:16)
at Deferred._.extend._WLModel [as _handleExec] (/var/www/html/api/node_modules/waterline/lib/waterline/methods/find-one.js:241:9)
at Deferred.exec (/var/www/html/api/node_modules/parley/lib/private/Deferred.js:286:10)
at Object.findOneRecord (/var/www/html/api/node_modules/sails/lib/hooks/blueprints/actions/findOne.js:37:4)
at /var/www/html/api/node_modules/sails/lib/router/bind.js:248:46
at routeTargetFnWrapper (/var/www/html/api/node_modules/sails/lib/router/bind.js:395:9)
at /var/www/html/api/node_modules/sails/lib/router/bind.js:458:14
at Layer.handle [as handle_request] (/var/www/html/api/node_modules/express/lib/router/layer.js:95:5) {
errno: -3001,
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'abmaster',
fatal: true
},
meta: {
host: 'test.anonderbazar.com',
port: 3306,
schema: true,
adapter: 'sails-mysql',
url: 'mysql://abmaster:duY$1L#8rwof#test.anonderbazar.com:3306/anonderbazaar',
connectTimeout: 20000,
identity: 'default'
}
}
at Object.findOneRecord (/var/www/html/api/node_modules/sails/lib/hooks/blueprints/actions/findOne.js:36:4)
at /var/www/html/api/node_modules/sails/lib/router/bind.js:248:46
at routeTargetFnWrapper (/var/www/html/api/node_modules/sails/lib/router/bind.js:395:9)
at /var/www/html/api/node_modules/sails/lib/router/bind.js:458:14
at Layer.handle [as handle_request] (/var/www/html/api/node_modules/express/lib/router/layer.js:95:5)
at next (/var/www/html/api/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/var/www/html/api/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/var/www/html/api/node_modules/express/lib/router/layer.js:95:5)
at /var/www/html/api/node_modules/express/lib/router/index.js:281:22
at param (/var/www/html/api/node_modules/express/lib/router/index.js:354:14)
at param (/var/www/html/api/node_modules/express/lib/router/index.js:365:14)
at Function.process_params (/var/www/html/api/node_modules/express/lib/router/index.js:410:3)
at next (/var/www/html/api/node_modules/express/lib/router/index.js:275:10)
at next (/var/www/html/api/node_modules/express/lib/router/route.js:127:14)
at alwaysAllow (/var/www/html/api/node_modules/sails/lib/hooks/policies/index.js:178:16)
at routeTargetFnWrapper (/var/www/html/api/node_modules/sails/lib/router/bind.js:395:9)
at /var/www/html/api/node_modules/sails/lib/router/bind.js:458:14
at Layer.handle [as handle_request] (/var/www/html/api/node_modules/express/lib/router/layer.js:95:5)
at next (/var/www/html/api/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/var/www/html/api/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/var/www/html/api/node_modules/express/lib/router/layer.js:95:5)
at /var/www/html/api/node_modules/express/lib/router/index.js:281:22
at param (/var/www/html/api/node_modules/express/lib/router/index.js:354:14)
at param (/var/www/html/api/node_modules/express/lib/router/index.js:365:14)
at Function.process_params (/var/www/html/api/node_modules/express/lib/router/index.js:410:3)
at next (/var/www/html/api/node_modules/express/lib/router/index.js:275:10)
at next (/var/www/html/api/node_modules/express/lib/router/route.js:127:14)
at Hook.expressMiddleware (/var/www/html/api/node_modules/sails/lib/hooks/i18n/index.js:205:14)
Any kind of help from anyone will be much appreciated.
I had this problem, my problem was that the password of my user had an '#' and in the connection there was also one, change the password and solve the error
Related
I am trying to create a mysql2 connection to a local mysql-Database in a jest-Test on macOS using typescript. And the call to connect() hangs.
Environment:
MacOS: High Sierra (10.13.6)
MySQL: 8.0.18
Typescript: 3.7.2
mysql2: 2.0.1
nodejs: v10.16.3
I am using the promise-Wrapper. The code looks like this:
import { createConnection, ConnectionOptions, Connection } from 'mysql2/promise'
...
async openConnection(options: ConnectionOptions): Promise<Connection> {
console.log('About to create mysql connection using options ', options);
const connection = await createConnection(options);
console.log('Connection created => about to call connect()');
await connection.connect();
console.log('Connection created => connect() returned'); // this line is never reached!
....
return connection;
}
I already added the debug-Option and this is the output:
Dieters-MBP-6:db-typescript rehdie$ node_modules/.bin/jest src/tests/mysql/mysql-connection.spec.ts --testNamePattern="Should open connection"
console.log src/lib/mysql/driver/mysql-driver.ts:21
About to create mysql connection using options { user: 'mysql-test',
password: '1q2w3e4r',
host: 'localhost',
port: 3306,
database: 'mysql_test_db',
charset: 'latin1_swedish_ci',
connectTimeout: 5000,
debug: true }
console.log node_modules/mysql2/lib/connection.js:425
Add command: ClientHandshake
console.log node_modules/mysql2/lib/connection.js:381
raw: 0a382e302e31380018000000277919626469296e00ffffff0200ffc715000000000000000000006d6335316a3c3d454220053a0063616368696e675f736861325f70617373776f726400
console.error console.js:274
Trace:
at Connection.handlePacket (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:387:17)
at PacketParser.Connection.packetParser.p [as onPacket] (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:70:12)
at PacketParser.executeStart (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.Connection.stream.on.data (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:77:25)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
console.log node_modules/mysql2/lib/connection.js:395
0 undefined ==> ClientHandshake#unknown name(0,,78)
console.log node_modules/mysql2/lib/commands/client_handshake.js:96
Server hello packet: capability flags:3355443199=(long password, found rows, long flag, connect with db, no schema, compress, odbc, local files, ignore space, protocol 41, interactive, ssl, ignore sigpipe, transactions, reserved, secure connection, multi statements, multi results, ps multi results, plugin auth, connect attrs, plugin auth lenenc client data, can handle expired passwords, session track, deprecate eof, ssl verify server cert, remember options)
console.log node_modules/mysql2/lib/commands/client_handshake.js:41
Sending handshake packet: flags:11203535=(long password, found rows, long flag, connect with db, odbc, local files, ignore space, protocol 41, ignore sigpipe, transactions, reserved, secure connection, multi results, plugin auth, plugin auth lenenc client data, session track)
console.log node_modules/mysql2/lib/connection.js:253
0 24 <== ClientHandshake#unknown name(1,,104)
console.log node_modules/mysql2/lib/connection.js:257
0 24 <== 64000001cff3aa00000000000800000000000000000000000000000000000000000000006d7973716c2d746573740014a13dd11599725225bcae39464cc3700a5fa085fc6d7973716c5f746573745f6462006d7973716c5f6e61746976655f70617373776f726400
console.log node_modules/mysql2/lib/connection.js:381
raw: fe63616368696e675f736861325f70617373776f726400277919626469296e6d6335316a3c3d454220053a00
console.error console.js:274
Trace:
at Connection.handlePacket (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:387:17)
at PacketParser.Connection.packetParser.p [as onPacket] (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:70:12)
at PacketParser.executeStart (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.Connection.stream.on.data (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:77:25)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
console.log node_modules/mysql2/lib/connection.js:395
0 24 ==> ClientHandshake#unknown name(2,,48)
console.log node_modules/mysql2/lib/connection.js:253
0 24 <== ClientHandshake#unknown name(3,,36)
console.log node_modules/mysql2/lib/connection.js:257
0 24 <== 20000003374930d53dd94bc2dbe6b54e4b83cd628658a1984656eb6ee4f31d7df596ce36
console.log node_modules/mysql2/lib/connection.js:381
raw: 0103
console.error console.js:274
Trace:
at Connection.handlePacket (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:387:17)
at PacketParser.Connection.packetParser.p [as onPacket] (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:70:12)
at PacketParser.executeStart (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.Connection.stream.on.data (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:77:25)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
console.log node_modules/mysql2/lib/connection.js:395
0 24 ==> ClientHandshake#unknown name(4,,6)
console.log node_modules/mysql2/lib/connection.js:381
raw: 000000024000000010010e0d6d7973716c5f746573745f6462
console.error console.js:274
Trace:
at Connection.handlePacket (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:387:17)
at PacketParser.Connection.packetParser.p [as onPacket] (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:70:12)
at PacketParser.executeStart (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.Connection.stream.on.data (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:77:25)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
console.log node_modules/mysql2/lib/connection.js:395
0 24 ==> ClientHandshake#unknown name(5,maybeOK,29)
console.log src/lib/mysql/driver/mysql-driver.ts:24
Connection created => about to call connect()
RUNS src/tests/mysql/mysql-connection.spec.ts
When I perform a show process list in mysql, I see a new process with Command 'Sleep' (state is empty and info is null).
Any ideas?
You need to ensure that node is using the system time and not fake timers. Add the below line immediately after your imports in the test file
jest.useRealTimers();
Or better still you can set timers to real in your jest config
"timers":"real"
I am transferring a node app from one server to another using different domain name.
I have setup everything but I cannot login to the control panel of the app which I have created, I am getting the following error.
{ Error: ER_NO_DEFAULT_FOR_FIELD: Field 'origin' doesn't have a default value
at Query.Sequence._packetToError (/var/www/node/node_modules/mysql/lib/pro tocol/sequences/Sequence.js:47:14)
at Query.ErrorPacket (/var/www/node/node_modules/mysql/lib/protocol/sequen ces/Query.js:77:18)
at Protocol._parsePacket (/var/www/node/node_modules/mysql/lib/protocol/Pr otocol.js:278:23)
at Parser.write (/var/www/node/node_modules/mysql/lib/protocol/Parser.js:7 6:12)
at Protocol.write (/var/www/node/node_modules/mysql/lib/protocol/Protocol. js:38:16)
at Socket.<anonymous> (/var/www/node/node_modules/mysql/lib/Connection.js: 91:28)
at Socket.<anonymous> (/var/www/node/node_modules/mysql/lib/Connection.js: 502:10)
at Socket.emit (events.js:189:13)
at Socket.EventEmitter.emit (domain.js:441:20)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
--------------------
at Protocol._enqueue (/var/www/node/anode_modules/mysql/lib/protocol/Protoc ol.js:144:48)
at Connection.query (/var/www/node/node_modules/mysql/lib/Connection.js:20 0:25)
at Object.managerLogin (/var/www/node/node_modules/login/index.js:58:15)
at callbackFunction (/var/www/node/routes/index.js:62:16)
at Layer.handle [as handle_request] (/var/www/node/node_modules/express/lib/router/ layer.js:95:5)
at next (/var/www/node/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/var/www/node/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/var/www/node/node_modules/express/lib/router/ layer.js:95:5)
at /var/www/node/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/var/www/node/node_modules/express/lib/router/index.js: 330:12)
at next (/var/www/node/node_modules/express/lib/router/index.js:271:10)
at /var/www/node/app.js:55:7
at Layer.handle [as handle_request] (/var/www/node/node_modules/express/lib/router/ layer.js:95:5)
at trim_prefix (/var/www/node/node_modules/express/lib/router/index.js:312:13)
at /var/www/node/node_modules/express/lib/router/index.js:280:7
at Function.process_params (/var/www/node/node_modules/express/lib/router/index.js: 330:12)
code: 'ER_NO_DEFAULT_FOR_FIELD',
errno: 1364,
sqlMessage: 'Field \'origin\' doesn\'t have a default value',
sqlState: 'HY000',
index: 0,
sql:
'INSERT INTO userLog SET userId = 2, token = \'9d99a1a0-7350-11e9-9671-95abec1f75f6\', ip = \'\', browser = \'\', isLog = \'y\', isValid = \'y\'' }
Cannot figure this out what is happening,app was running file in the old server.
Debugged it, found it's a mysql bug, edited etc/mysql/my.cnf with [mysqld]
port = 3306
sql-mode=""
reloaded mysql, and it worked for me!
I am integrating linkedin authentication with my node.js by passport-linkedin.
It works fine initially. I am redirected to login/signup page. User is entering their details but then when it is coming to authentication I get the error
InternalOAuthError: Failed to obtain access token
at Strategy.OAuth2Strategy._createOAuthError (C:\Users\SU40006113\Desktop\second\node_modules\passport-oauth2\lib\strategy.js:379:17)
at C:\Users\SU40006113\Desktop\second\node_modules\passport-oauth2\lib\strategy.js:166:45
at C:\Users\SU40006113\Desktop\second\node_modules\oauth\lib\oauth2.js:199:18
at ClientRequest.<anonymous> (C:\Users\SU40006113\Desktop\second\node_modules\oauth\lib\oauth2.js:170:5)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at TLSSocket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
I checked on stack overflow and got to know that it is because of corporate proxy. I added
var HttpsProxyAgent = require('https-proxy-agent');
if (process.env['https_proxy']) {
httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy']);
}
and
options.agent = httpsProxyAgent;
in oauth2.js. But now I am getting this error
ReferenceError: httpsProxyAgent is not defined
at exports.OAuth2._request (C:\Users\SU40006113\Desktop\second\node_modules\oauth\lib\oauth2.js:126:19)
at exports.OAuth2.getOAuthAccessToken (C:\Users\SU40006113\Desktop\second\node_modules\oauth\lib\oauth2.js:197:8)
at loaded (C:\Users\SU40006113\Desktop\second\node_modules\passport-oauth2\lib\strategy.js:164:20)
at NullStore.verify (C:\Users\SU40006113\Desktop\second\node_modules\passport-oauth2\lib\state\null.js:9:3)
at Strategy.OAuth2Strategy.authenticate (C:\Users\SU40006113\Desktop\second\node_modules\passport-oauth2\lib\strategy.js:210:26)
at attempt (C:\Users\SU40006113\Desktop\second\node_modules\passport\lib\middleware\authenticate.js:361:16)
at authenticate (C:\Users\SU40006113\Desktop\second\node_modules\passport\lib\middleware\authenticate.js:362:7)
at Layer.handle [as handle_request] (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\index.js:275:10)
at Function.handle (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\index.js:174:3)
at router (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\index.js:47:12)
I have installed https-proxy-agent.
What's causing the error?
I am attempting to follow this tutorial on using using node, Express, and postgresql to build and API. All my code for this can be found on Github.
In my server/routes/index.js is the following (the numbering being line numbers).
1: app.get('/api/todos', todosController.list);
2: // app.post('/api/todos/:todoId/items', todoItemsController.create);
3: app.post('/api/todos', todosController.create);
4: app.get('/api/todos/:todoId', todosController.retrieve);
5: app.put('/api/todos/:todoId', todosController.update);
6: app.delete('/api/todos/:todoId', todosController.destroy);
I am having two problems.
The first problem is lines 4 and 5 don't work (all of the other lines do minus line 2). When I use postman/browser to test them I get this error
ReferenceError: TodoItem is not defined
at retrieve (/Users/X-lem/Development/TestAPI/server/controllers/todos.js:25:20)
at Layer.handle [as handle_request] (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/layer.js:95:5)
at /Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:281:22
at param (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:354:14)
at param (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:365:14)
at Function.process_params (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:410:3)
at next (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:275:10)
at urlencodedParser (/Users/X-lem/Development/TestAPI/node_modules/body-parser/lib/types/urlencoded.js:91:7)
at Layer.handle [as handle_request] (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:317:13)
at /Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:335:12)
at next (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:275:10)
at jsonParser (/Users/X-lem/Development/TestAPI/node_modules/body-parser/lib/types/json.js:109:7)
at Layer.handle [as handle_request] (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:317:13)
at /Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:335:12)
at next (/Users/X-lem/Development/TestAPI/node_modules/express/lib/router/index.js:275:10)
Secondly, when I uncomment line 2 the console crashes and I get this error.
ReferenceError: todoItemsController is not defined
at module.exports (/Users/X-lem/Development/TestAPI/server/routes/index.js:9:40)
at Object.<anonymous> (/Users/X-lem/Development/TestAPI/app.js:16:27)
at Module._compile (module.js:612:30)
at Object.Module._extensions..js (module.js:623:10)
at Module.load (module.js:531:32)
at tryModuleLoad (module.js:494:12)
at Function.Module._load (module.js:486:3)
at Module.require (module.js:556:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/X-lem/Development/TestAPI/bin/www:3:13)
at Module._compile (module.js:612:30)
at Object.Module._extensions..js (module.js:623:10)
at Module.load (module.js:531:32)
at tryModuleLoad (module.js:494:12)
at Function.Module._load (module.js:486:3)
at Function.Module.runMain (module.js:653:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
[nodemon] app crashed - waiting for file changes before starting...
I am new to building API's and am trying to teach myself how to do it. I have tried a number of different troubleshooting methods with no avail. Any help is appreciated, thank you.
Hope I can help a little bit. Your problem #2 was because you did mistype. Please, take a look at your routes/index.js file. You imported controllers to the variable todosController, but on the 9-th line you are using not defined variable todoItemsController. So, just
app.post('/api/todos/:todoId/items', todosController.create); will work.
I installed meanjs in my OpenSUSE distro, however when I run npm start, here's what I get:
+ Important warning: config.domain is empty. It should be set to the fully qualified domain of the app.
Unhandled rejection MongoError: not authorized on mean-dev to execute command { listIndexes: "sessions", cursor: {} }
at Function.MongoError.create (/home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/error.js:31:11)
at queryCallback (/home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/cursor.js:212:36)
at /home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/connection/pool.js:469:18
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
From previous event:
at MongoStore.setAutoRemoveAsync (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:129:40)
at MongoStore.handleNewConnectionAsync (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:121:18)
at MongoStore (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:96:26)
at Object.module.exports.initSession (/home/tasher/Projects/meanjs_test/config/lib/express.js:120:12)
at Object.module.exports.init (/home/tasher/Projects/meanjs_test/config/lib/express.js:243:8)
at /home/tasher/Projects/meanjs_test/config/lib/app.js:25:23
at /home/tasher/Projects/meanjs_test/config/lib/mongoose.js:35:21
at process._tickCallback (internal/process/next_tick.js:109:7)
Unhandled rejection MongoError: not authorized on mean-dev to execute command { listIndexes: "sessions", cursor: {} }
at Function.MongoError.create (/home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/error.js:31:11)
at queryCallback (/home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/cursor.js:212:36)
at /home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/connection/pool.js:469:18
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
From previous event:
at MongoStore.setAutoRemoveAsync (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:129:40)
at MongoStore.handleNewConnectionAsync (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:121:18)
at MongoStore (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:96:26)
at module.exports (/home/tasher/Projects/meanjs_test/config/lib/socket.io.js:73:20)
at Object.module.exports.configureSocketIO (/home/tasher/Projects/meanjs_test/config/lib/express.js:214:38)
at Object.module.exports.init (/home/tasher/Projects/meanjs_test/config/lib/express.js:258:14)
at /home/tasher/Projects/meanjs_test/config/lib/app.js:25:23
at /home/tasher/Projects/meanjs_test/config/lib/mongoose.js:35:21
at process._tickCallback (internal/process/next_tick.js:109:7)
error: uncaughtException: getaddrinfo ENOTFOUND linux-hcjz.suse date=Mon Aug 28 2017 22:46:50 GMT+0100 (WEST), pid=4497, uid=1000, gid=100, cwd=/home/tasher/Projects/meanjs_test, execPath=/usr/bin/node6, version=v6.11.1, argv=[/usr/bin/node6, /home/tasher/Projects/meanjs_test/server.js], rss=97284096, heapTotal=69029888, heapUsed=48863040, external=20182576, loadavg=[0.6513671875, 0.61669921875, 0.43505859375], uptime=3056
Error: getaddrinfo ENOTFOUND linux-hcjz.suse
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
I have re-installed meanjs twice but in vain. Mongo is also running. By the way:
tasher#linux-hcjz:~/Projects/meanjs_test> node -v
v6.11.1
tasher#linux-hcjz:~/Projects/meanjs_test> npm6 -v
3.10.10
Any thoughts?
try adding execution permission to your mean-dev
chmod 755 path_for_package/mean-dev
replace path path_for_package with your path