0

I am following this tutorial from ArangoDB.com. It is about creating Arango database using node.js. I am doing it on OS X.

After executing in node code:

    > Database = require('arangojs').Database;
      [Function: Database]
    > db = new Database('http://127.0.0.1:8529');
      Database {
  _connection: 
   Connection {
     config: 
      { url: 'http://127.0.0.1:8529',
        databaseName: '_system',
        arangoVersion: 20300,
        agentOptions: [Object],
        headers: [Object] },
     _request: [Function: request],
     promisify: [Function] },
  _api: 
   Route {
     _connection: 
      Connection {
        config: [Object],
        _request: [Function: request],
        promisify: [Function] },
     _path: '_api',
     _headers: undefined },
  name: '_system' }

    > db.createDatabase('mydb', function (err) {
       if (!err) console.log('Database created');
       else console.error('Failed to create database:', err);
     });

I am getting ECONNREFUSED error:

Failed to create database: { [Error: connect ECONNREFUSED 127.0.0.1:8529]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 8529,
  request: 
   ClientRequest {
     domain: 
      Domain {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        members: [] },
     _events: { response: [Object], error: [Function] },
     _eventsCount: 2,
     _maxListeners: undefined,
     output: [],
     outputEncodings: [],
     outputCallbacks: [],
     outputSize: 0,
     writable: true,
     _last: false,
     chunkedEncoding: false,
     shouldKeepAlive: true,
     useChunkedEncodingByDefault: true,
     sendDate: false,
     _removedHeader: { 'content-length': false },
     _contentLength: null,
     _hasBody: true,
     _trailer: '',
     finished: true,
     _headerSent: true,
     socket: 
      Socket {
        _connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: false,
        domain: [Object],
        _events: [Object],
        _eventsCount: 10,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        destroyed: true,
        bytesRead: 0,
        _bytesDispatched: 0,
        _sockname: null,
        _pendingData: [Object],
        _pendingEncoding: '',
        server: null,
        _server: null,
        parser: [Object],
        _httpMessage: [Circular],
        read: [Function],
        _consuming: true,
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1 },
     connection: 
      Socket {
        _connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: false,
        domain: [Object],
        _events: [Object],
        _eventsCount: 10,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        destroyed: true,
        bytesRead: 0,
        _bytesDispatched: 0,
        _sockname: null,
        _pendingData: [Object],
        _pendingEncoding: '',
        server: null,
        _server: null,
        parser: [Object],
        _httpMessage: [Circular],
        read: [Function],
        _consuming: true,
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1 },
     _header: 'POST /_db/_system/_api/database HTTP/1.1\r\ncontent-type: application/json\r\ncontent-length: 15\r\nx-arango-version: 20300\r\nHost: 127.0.0.1:8529\r\nConnection: keep-alive\r\n\r\n',
     _headers: 
      { 'content-type': 'application/json',
        'content-length': 15,
        'x-arango-version': 20300,
        host: '127.0.0.1:8529' },
     _headerNames: 
      { 'content-type': 'content-type',
        'content-length': 'content-length',
        'x-arango-version': 'x-arango-version',
        host: 'Host' },
     _onPendingData: null,
     agent: 
      Agent {
        domain: [Object],
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        defaultPort: 80,
        protocol: 'http:',
        options: [Object],
        requests: {},
        sockets: [Object],
        freeSockets: {},
        keepAliveMsecs: 1000,
        keepAlive: true,
        maxSockets: 3,
        maxFreeSockets: 256 },
     socketPath: undefined,
     method: 'POST',
     path: '/_db/_system/_api/database',
     parser: 
      HTTPParser {
        '0': [Function: parserOnHeaders],
        '1': [Function: parserOnHeadersComplete],
        '2': [Function: parserOnBody],
        '3': [Function: parserOnMessageComplete],
        '4': null,
        _headers: [],
        _url: '',
        _consumed: false,
        socket: [Object],
        incoming: null,
        outgoing: [Circular],
        maxHeaderPairs: 2000,
        onIncoming: [Function: parserOnIncomingClient] } } }

Unfortunately I can't localise error. I was searching for similar porblems but didn't find any solutions. I don't have much experience with these technologies and I am just starting ArangoDB now.

I would be grateful for any tips how to solve it and/or any other materials how to start with ArangoDB.

2
  • 1
    Did you try running all that as a node file copy paste that code into a server.js then do node server.js Commented May 4, 2016 at 12:25
  • Thanks, I chcecked it now and it worked like it shoud have. Commented May 4, 2016 at 12:31

2 Answers 2

3

The error indicates that the client could not connect, presumably ArangoDB is not running at port 8529 on localhost, hasn't been started or hasn't finished starting.

The tutorial should work from the node shell but you may have to avoid line breaks (e.g. before a . when calling a method like .then). The code in the examples has been formatted for readability, the screenshots may be safer if you want something to follow along.

Sign up to request clarification or add additional context in comments.

1 Comment

I think problem could have been in not running(yet) server. Later it started working without problems.
2

In general if you have multiple line of code that you need to run using node it is best to create a JavaScript file that contains all the code you want to run such as script.js. To run that code you use node script.js. This will cause node to evaluate your code line by line and (potentially) persistently keep the code running the code (things like a server would do this).

Using the node shell (aka just running node directly) will not be a good strategy to have persistently running code.

So in conclusion: place any server code in a script.js then run it with the command node script.js inside of a bash shell (where node is installed).

It very likely code not start a server and persistently consume a port while inside the shell.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.