简体   繁体   中英

how to run node.js server when button clicked in react native

I have a node.js server file for sending push notification.(file name: server.js)
It's working successfully when i write "node server.js" in terminal.
But i dont want to run node.js server like this manually.

I want to run server when button clicked in react native. I tried this document but it is not supported on Windows10.
How can i do that?


const fcm = require('fcm-notification');
const FCM = new fcm('./bildirim8-4090c-firebase.json');
const token =
  'exe-079BQlU:APA91bEI0UFim_Sl4G8mZbfbQ84obrkaXQ47bUlmx_Po5ntkh5hp1BbiNSP_lh28cmUEvUaW5VSe765_yRSVuFyPv5wqgFhh0Jat-Lj3kGZGB-I37lCvg8Ab3q9TRNdOpPBiolS10tmJ';

var message = {
  data: {
    //This is only optional, you can send any data
    score: '850',
    time: '2:45',
  },
  notification: {
    title: 'inside node.js server',
    body: 'message sent!',
  },
  token: token,
};

FCM.send(message, function(err, response) {
  if (err) {
    console.log('error found', err);
  } else {
    console.log('response here', response);
  }
});

Your button needs to send a request to the backend. The response is the one to start the server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM