Grandstack - npm run seedDb - ECONNREFUSED

Hi!

So I got this error using npm run seedDb in the Grand stack starter project:

(base) Kaspers-MBP:api kasperknudsen$ npm run seedDb

> grand-stack-starter-api@0.0.1 seedDb /Users/kasperknudsen/grand-stack-starter-master/api
> babel-node src/seed/seed-db.js

ApolloError: Network error: request to http://localhost:4000/ failed, reason: connect ECONNREFUSED 127.0.0.1:4000
    at new ApolloError (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/apollo-client/bundle.umd.js:92:26)
    at Object.error (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/apollo-client/bundle.umd.js:1329:28)
    at notifySubscription (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:134:18)
    at onNotify (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:165:3)
    at SubscriptionObserver.error (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:224:7)
    at /Users/kasperknudsen/grand-stack-starter-master/api/node_modules/apollo-client/bundle.umd.js:1106:37
    at Set.forEach (<anonymous>)
    at Object.error (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/apollo-client/bundle.umd.js:1105:21)
    at notifySubscription (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:134:18)
    at onNotify (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:165:3) {
  graphQLErrors: [],
  networkError: FetchError: request to http://localhost:4000/ failed, reason: connect ECONNREFUSED 127.0.0.1:4000
      at ClientRequest.<anonymous> (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/node-fetch/lib/index.js:1455:11)
      at ClientRequest.emit (events.js:210:5)
      at ClientRequest.EventEmitter.emit (domain.js:476:20)
      at Socket.socketErrorListener (_http_client.js:406:9)
      at Socket.emit (events.js:210:5)
      at Socket.EventEmitter.emit (domain.js:476:20)
      at emitErrorNT (internal/streams/destroy.js:92:8)
      at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
      at processTicksAndRejections (internal/process/task_queues.js:80:21) {
    message: 'request to http://localhost:4000/ failed, reason: connect ECONNREFUSED 127.0.0.1:4000',
    type: 'system',
    errno: 'ECONNREFUSED',
    code: 'ECONNREFUSED'
  },
  message: 'Network error: request to http://localhost:4000/ failed, reason: connect ECONNREFUSED 127.0.0.1:4000',
  extraInfo: undefined

Any tips?

What happens when you call http://localhost:4000/graphql in the browser?
Perhaps it's a problem with the port number.
What is the value of GRAPHQL_LISTEN_PORT in /api/src/.env ?

GRAPHQL_URI=http://localhost:4000

Changed it to 4001 since that's where I run [http://localhost:4001/graphql] and got this error instead..:

> babel-node src/seed/seed-db.js

ApolloError: Network error: Unexpected token < in JSON at position 0
    at new ApolloError (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/apollo-client/bundle.umd.js:92:26)
    at Object.error (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/apollo-client/bundle.umd.js:1329:28)
    at notifySubscription (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:134:18)
    at onNotify (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:165:3)
    at SubscriptionObserver.error (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:224:7)
    at /Users/kasperknudsen/grand-stack-starter-master/api/node_modules/apollo-client/bundle.umd.js:1106:37
    at Set.forEach (<anonymous>)
    at Object.error (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/apollo-client/bundle.umd.js:1105:21)
    at notifySubscription (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:134:18)
    at onNotify (/Users/kasperknudsen/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:165:3) {
  graphQLErrors: [],
  networkError: SyntaxError [ServerParseError]: Unexpected token < in JSON at position 0
      at JSON.parse (<anonymous>)
      at /Users/kasperknudsen/grand-stack-starter-master/api/node_modules/apollo-link-http/node_modules/apollo-link-http-common/src/index.ts:131:23
      at processTicksAndRejections (internal/process/task_queues.js:93:5) {
    name: 'ServerParseError',
    response: Response {
      size: 0,
      timeout: 0,
      [Symbol(Body internals)]: [Object],
      [Symbol(Response internals)]: [Object]
    },
    statusCode: 404,
    bodyText: '<!DOCTYPE html>\n' +
      '<html lang="en">\n' +
      '<head>\n' +
      '<meta charset="utf-8">\n' +
      '<title>Error</title>\n' +
      '</head>\n' +
      '<body>\n' +
      '<pre>Cannot POST /</pre>\n' +
      '</body>\n' +
      '</html>\n'
  },
  message: 'Network error: Unexpected token < in JSON at position 0',
  extraInfo: undefined
}

To my understanding, the relevant entries in your .env file should look like this:

GRAPHQL_LISTEN_PORT=4001
GRAPHQL_URI=http://localhost:4001/graphql

The /graphql part should not be omitted. The seedDB.js script reads this value:

const client = new ApolloClient({
  link: new HttpLink({ uri: process.env.GRAPHQL_URI, fetch }),
  cache: new InMemoryCache()
});

Hope that helps. I had some problems with the seedDB part in the beginning also, but today everything runs smoothly.

Thanks for helping but ending up still getting the ECONNREFUSED error with all the corrections..

I could reproduce the ECONNREFUSED error when the api server was not running (if I didn't run 'npm start' in the /api directory).
Which version of neo4j are you using?

1 Like

Actually solved it by re-clone the starter pack + re-installing npm.
Now my only problem is that I can't get the data from seedDb visually in Neo desktop.