Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在本地计算机上处理来自arduino的express中的同时请求_Node.js_Firebase_Express - Fatal编程技术网

Node.js 在本地计算机上处理来自arduino的express中的同时请求

Node.js 在本地计算机上处理来自arduino的express中的同时请求,node.js,firebase,express,Node.js,Firebase,Express,我正在为我的arduino创建一个本地Web服务器(在我的windows PC上),以便向其发送POST请求。由于Arduino无法支持Firebase所需的HTTPS,因此这些请求中的数据将通过本地Web服务器写入Cloud Firestore。我已使用express设置了服务器: const express = require('express'); const bodyParser = require('body-parser') const app = express(); const

我正在为我的arduino创建一个本地Web服务器(在我的windows PC上),以便向其发送POST请求。由于Arduino无法支持Firebase所需的HTTPS,因此这些请求中的数据将通过本地Web服务器写入Cloud Firestore。我已使用express设置了服务器:

const express = require('express');
const bodyParser = require('body-parser')
const app = express();
const HOST_PORT = 6500;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(bodyParser.raw());

app.get('/',(req,res,next)=>{
    return res.status(200).send()
})

app.post('/',(req,res,next)=>{
    return res.status(200).send()
})

app.post('/machine',(req,res,next)=>{
    console.log('Got body:', req.body);
    //Send to firebase here use async/await or just send the request? 
    return res.status(200).send()
})

app.listen(HOST_PORT, () => console.log(`Started server at http://localhost:${HOST_PORT}!`));

如果三个arduinos向
/machine
发出请求,是否会创建该函数的三个实例?我想知道,因为我想知道如何处理Web服务器上的同时请求。我只是调用firebase而不是等待结果吗?

这是Node.js异步运行时的一个优点:当您的/机器路由等待第一个请求时,它可以处理其他请求,没有问题

app.post('/machine', async (req,res,next)=>{
    console.log('Got body:', req.body);
    await firestore.doc("collection/docId").set({foo: "bar"})
    return res.status(200).send()
})
可以找到更多信息