Its simple to actually work with NodeJS. Here's is the link that uses MongoDB but can also be implemented on MYSQL which minimal modifications. Android Login Registration System with Node.js and MongoDB - Server #1
Your response is private.
Is this a useful answer to your question?
Baalateja Kataru

There are two ways to do this, either using the HttpURLConnection class or using the HTTP library for Android called Volley. I’ll be using the latter here.

First, if you’re running Express - set up routing to handle the post requests that your server is going to recieve:

  1. var express = require('express');
  2. var app = express();
  3. const bodyParser = require('body-parser');
  4. var server = app.listen(3000);
  5. app.use(bodyParser.json());
  6. app.use(bodyParser.urlencoded({ extended: true }));
  7. app.post('/postdata', (req, res) => {
  8. var data = req.body.data; // your data
  9. console.log(data);
  10. // do something with that data (write to a DB, for instance)
  11. res.status(200).json({
  12. message: "JSON Data received successfully"
  13. });
  14. });

Next, you need to write the Volley POST request in an Activity that sends data in JSON format, which is the ideal way of communication with a RESTful Node server. In Android Studio it’s done like this:

  1. public class MainActivity extends AppCompatActivity {
  2. Button RequestButton; // button which on clicking, sends the request
  3. TextView DisplayText; // a text field to display the request response
  4. TextView DataField; // a text field where the data to be sent is entered
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main);
  9. RequestButton = (Button) findViewById(R.id.RequestButton);
  10. DataField = (TextView) findViewById(R.id.DataField);
  11. DisplayText = (TextView) findViewById(R.id.DisplayText);
  12. final RequestQueue queue = Volley.newRequestQueue(this);
  13. final String url = "http://serverdomainorip/postdata"; // your URL
  14. queue.start();
  15. RequestButton.setOnClickListener(new View.OnClickListener() {
  16. @Override
  17. public void onClick(View v) {
  18. HashMap<String, String> params = new HashMap<String,String>();
  19. params.put("data", DataField.getText().toString()); // the entered data as the JSON body.
  20. JsonObjectRequest jsObjRequest = new
  21. JsonObjectRequest(Request.Method.POST,
  22. url,
  23. new JSONObject(params),
  24. new Response.Listener<JSONObject>() {
  25. @Override
  26. public void onResponse(JSONObject response) {
  27. try {
  28. DisplayText.setText(response.getString("message"));
  29. } catch (JSONException e) {
  30. e.printStackTrace();
  31. }
  32. }
  33. }, new Response.ErrorListener() {
  34. @Override
  35. public void onErrorResponse(VolleyError error) {
  36. DisplayText.setText("That didn't work!");
  37. }
  38. });
  39. queue.add(jsObjRequest);
  40. }
  41. });
  42. }
  43. }

Essentially, the above code takes the data entered in a text field and sends it as the body of a POST request to your node server on clicking a button on the page. Once the response is received, it sets that response as the text of another text field on the page for you to see it. Here, The data is sent as JSON by wrapping it in a JSON object and the response received is also in JSON format.