Nik Nik - 1 year ago 81
Node.js Question

How to access Angular Js data from nodejs

Hi in my angular js file, I have patient objects which contain name, number and appointment date. In my node js file, I use twilio to send a text a patient. What I want to know is how to get the number from the angular js file in order to use it in my node Js file so I can send the patient a text. Thanks.

here is the part of server.js where I send the text message'/testtwilio', function(req,res){

var cheerio = require('cheerio'),
$ = cheerio.load('file.html'),
fs = require('fs');
fs.readFile('./views/index.html', function (err, html) {
if (err) {
throw err;
} else {
$ = cheerio.load(html.toString());
to: '{{patient.number}}',
from: '+16173935460',
body: 'Text sent using NodeJS'
}, function(err, data){


Here is the patient object in the MainController.js

$scope.patients = [
name: 'John Smith',
date: "12/22/2016",
number: 1829191844
name: 'Matt',
date: "09/15/2016",
number: 1829198344
name: 'John',
date: "08/25/2016",
number: 1829198844


Answer Source

Pass the data from the front end to the backend? Have angular call a route on your backend with the data you need and access it with the req.params object.

Is your server.js a node.js controller?

In the angular controller you could import $http and just do a ${myparams}, /myRoute, function(results){console.log(results)})

Like Mike says. The only way to really share files between the front end and the backend is if the files are JSON as that can be read by Angular and Node. However, I usually just use this for static configuration files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download