1

I am new to arangodb and node. I could be able to connect to the database from node server and successfully able to receive queries or id from collections and even edge collections. All these were done simply by directly running the server.js file.

Now I would like to create function in node.js to able to receive the data from Arangodb for each individual task so that I can use this with the front end (Angular4) later. I have attached my server.js file. Can anyone suggest how to do it?

// BASE SETUP
// ## Assigning the values

const arangojs = require('arangojs');
const aqlQuery = arangojs.aqlQuery;
const now = Date.now();

// ## Const variables for connecting to ArangoDB database

const host = '192.000.00.000'
const port = '8529'
const username = 'xyz'
const password = 'xyz'
const path = '/_db/sgcdm_app/_api/'
const database = 'sgcdm_app'

// ## Connection to ArangoDB

db = new arangojs.Database({
url: http://${host}:${port},
databaseName: database
});
db.useBasicAuth(username, password);

const collection = db.edgeCollection('included_in');
const edge = collection.edge('included_in/595783');

//============

//## call the packages we need

var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');

//## configure app to use bodyParser()------// 

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var port1 = process.env.PORT || 8080; // set our port


// START THE SERVER

app.listen(port1);
console.log('Magic happens on port1 ' + port1);

1 Answer 1

1

Essentially, you want to build an API for Angular to consume.

I suggest you try the Express package for Nodejs. Here is the basic example you can follow.

Essentially you will just create a route with Express and return data. Each part of your Angular app that needs data will probably require a different route, although you can of course use route parameters to make things dynamic.

app.get('/', function (req, res) {
  res.send(collection.all())
})
Sign up to request clarification or add additional context in comments.

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.