Thursday, August 28, 2014

Post JSON to Nodejs from Angularjs

I'm struggling with the title of this post as I searched many ways but couldn't find something simple like this.
If you have any other name suggestions I'm totally open!
Here goes.

I wanted to send JSON from an AngularJS app and get it on my NodeJS side so I could do something with the data.

There may be better ways (Socket.IO anyone?) but here goes:

Here is my angularJS service:


And here is my nodejs page:

Install express, and body-parser (I think that's about all) and you should be able to send a message using
$message.create({ }); // That's a JSON object being passed in
Simple AngularJS controller

And Finally a simple HTML page for it.

Good Luck!
I hope that helps SOMEONE out there.

No comments:

Post a Comment