[单击本机时单击按钮时如何运行node.js服务器
我有一个用于发送推送通知的node.js服务器文件。(文件名:server.js)当我在终端中写“ node server.js”时,它工作正常。但是我不想手动运行像这样的node.js服务器。
我想在本地点击按钮时运行服务器。我尝试了this document,但Windows10不支持它。我该怎么办?
server.js
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);
}
});
回答如下:您的按钮需要向后端发送请求。响应是启动服务器的响应