OpenClassrooms-Student-Center / Project-10-Bank-API

9 stars 888 forks source link

npm run populate-db renvoi: Error: connect ECONNREFUSED 127.0.0.1:3001 #24

Open Emmanuel97423 opened 1 year ago

Emmanuel97423 commented 1 year ago

Est-ce normal que lorsqu'on exécute la commande npm run populate-db la réponse renvoyé est :

Error: connect ECONNREFUSED 127.0.0.1:3001
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3001,
  config: {
    url: 'http://localhost:3001/api/v1/user/signup',
    method: 'post',
    data: '{"firstName":"Tony","lastName":"Stark","email":"tony@stark.com","password":"password123"}',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json;charset=utf-8',
      'User-Agent': 'axios/0.19.2',
      'Content-Length': 89
    },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    validateStatus: [Function: validateStatus]
  },
  request: Writable {
    _writableState: WritableState {
      objectMode: false,
      highWaterMark: 16384,
      finalCalled: false,
      needDrain: false,
      ending: false,
      ended: false,
      finished: false,
      destroyed: false,
      decodeStrings: true,
      defaultEncoding: 'utf8',
      length: 0,
      writing: false,
      corked: 0,
      sync: true,
      bufferProcessing: false,
      onwrite: [Function: bound onwrite],
      writecb: null,
      writelen: 0,
      afterWriteTickInfo: null,
      bufferedRequest: null,
      lastBufferedRequest: null,
      pendingcb: 0,
      prefinished: false,
      errorEmitted: false,
      emitClose: true,
      autoDestroy: false,
      bufferedRequestCount: 0,
      corkedRequestsFree: [Object]
    },
    writable: true,
    _events: [Object: null prototype] {
      response: [Function: handleResponse],
      error: [Function: handleRequestError]
    },
    _eventsCount: 2,
    _maxListeners: undefined,
    _options: {
      protocol: 'http:',
      maxRedirects: 21,
      maxBodyLength: 10485760,
      path: '/api/v1/user/signup',
      method: 'POST',
      headers: [Object],
      agent: undefined,
      agents: [Object],
      auth: undefined,
      hostname: 'localhost',
      port: '3001',
      nativeProtocols: [Object],
      pathname: '/api/v1/user/signup'
    },
    _redirectCount: 0,
    _redirects: [],
    _requestBodyLength: 89,
    _requestBodyBuffers: [ [Object] ],
    _onNativeResponse: [Function],
    _currentRequest: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: false,
      _headerSent: true,
      socket: [Socket],
      connection: [Socket],
      _header: 'POST /api/v1/user/signup HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json;charset=utf-8\r\n' +
        'User-Agent: axios/0.19.2\r\n' +
        'Content-Length: 89\r\n' +
        'Host: localhost:3001\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'POST',
      insecureHTTPParser: undefined,
      path: '/api/v1/user/signup',
      _ended: false,
      res: null,
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'localhost',
      protocol: 'http:',
      _redirectable: [Circular],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    _currentUrl: 'http://localhost:3001/api/v1/user/signup',
    [Symbol(kCapture)]: false
  },
  response: undefined,
  isAxiosError: true,
  toJSON: [Function]
}
DamienL47 commented 10 months ago

J'ai le même problème ....

Elishaya13 commented 6 months ago

Il faut demarrer le serveur MongoDb en arriere plan

olafswan commented 5 months ago

J'ai le même problème @Elishaya13 tu peux m'en dire plus sur comment " demarrer le serveur MongoDb en arriere plan", stp ?

Elishaya13 commented 5 months ago

@olafswan il faut demarrer mongoDB, tu dois l'avoir installé c'est mis dans le readme regarde. Moi je suis sur macOS donc je passe par brew, il faut aussi être en version node 12. J'utilise NVM pour switch à la bonne version grâce a un fichier nvmrc, si tu ne connais pas je t'invite a te renseigner dessus c'est très pratique. Voici mon readme que j'ai mis à jour pour moi même et me rappeler (mais avec brew donc macOS, a toi de voir si tu n'es pas sur mac quelle est la facon de demarrer mongodb)

Install dependencies

npm install

Launch mongodb with brew

brew services start mongodb-community@6.0

To stop it

brew services stop mongodb-community@6.0

Switch back end version with nvm use (add .nvmrc file v12)

nvm use

Start local dev server

npm run dev:server

Populate database with two users

npm run populate-db

olafswan commented 5 months ago

Merci @Elishaya13, j'avais déjà suivi les indications du readme, je suis sur windows, j'ai pu résoudre le problème grace au [https://discord.gg/AYrND2SK](Discord DA - JavaScript React) : Changer 2 lignes dans le back pour connecter le serveur. Dans connexion.js: process.env.DATABASE_URL || 'mongodb://0.0.0.0/argentBankDB' Dans le fichier .env: DATABASE_URL="mongodb://0.0.0.0/argentBankDB"

C'est quand même du gros foutage de gueule tous ces projet baclés de la part de OC, pour prendre l'oseille il y a du monde pour corriger des erreurs qui sont présentes depuis plusieurs années sur les projets il y a personne ! Sur le discord depuis 2021 tout le monde se casse les dents. J'ai perdu 1 heure de session mentorat avec mon mentor pour même pas avoir résolu le problème à la fin. On fait une formation front-end on se retrouve a bricoler un back-end foireux pour pouvoir demarrer le projet...