Please help me to figure out the logic behind Express REST API. I am moving my self-education from pure AngularJS to MEAN stack, so please bear with me.
I have the following angular controller, which takes data from my contact form and put it into formData object.
app.controller('ContactCtrl', ['$scope', '$http', function($scope, $http){
$scope.formData = {};
$scope.submitForm = function() {
console.log($scope.formData);
$http.post('/sendEmail', $scope.formData);
}
}]);
In my routes/index.js file I have the following code to test If It can at least get to this route
router.get('/sendEmail', function(req, res) {
res.send('hello world');
});
When I submit form I am getting Error 500 from the server.
http://localhost:3000/sendEmail 500 (Internal Server Error)
Can somebody tell me what I am doing fundamentally wrong.
I was trying to find some docs or tutorials for beginners about this topic, but at this point I think I need some interactive human help. Can somebody explain
- Why I am getting 500 ERROR, why it's not simply rendering "Hello World"
- How to properly pass $scope.formData to Express and how the res. could look like.
Last question, is a bonus question, you can ignore it if you think it's too much, I still need to dig into nodemailer docs. 3. How to use this $scope.formData object that we passed to Express and use it here with nodemailer API to actually send email.
Thank you all in advance!
I really want to master MEAN, but getting hard times in putting it all together sometimes.
I am asking here, because there is really no "COMPLETE" MEAN stack tutorial on Contact forms. Maybe someone can make one.