如何从我的 react-app 启动节点脚本? [英] How can i start node script from my react-app?

查看:32
本文介绍了如何从我的 react-app 启动节点脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用按钮从 react-app 启动 node.js 脚本的最简单方法是什么?

What is the easiest way to launch a node.js script from a react-app by using a button?

我有一个带有两个按钮的简单应用 - 使用 Material.io

I've a simple app with two buttons - using Material.io

export default function ButtonsMenu() {
    const classes = useStyles();

    return (
    <Grid>
        <Grid item xs={12}>
            <Paper style={styles.Paper}>
                <Button onClick={activeLights} variant="contained" color="primary" className={classes.button}>
                    ON
                </Button>
                <Button onClick={inactiveLights}variant="contained" color="secondary" className={classes.button}>
                    OFF
                </Button>
            </Paper>
        </Grid>
    </Grid>
    );

我还有一个带 LED 条纹的 Arduino,我为它编写了 node.js 代码.如何从浏览器运行它?

I also have an Arduino with led stripe that i wrote a node.js code for. How can i run it from the browser?

我知道我需要一个节点服务器和一个客户端,但需要一些帮助我下一步该怎么做.

I know that i need a node server and a client, but need some help what should i do next.

我很感激任何 github 存储库等.

I would appreciate any github repository etc.

推荐答案

你不能那样做,ReactJs 是为了fornt使用,而是对node js服务器进行API调用,即使浏览器也会阻止你调用本地命令

You can't do that, ReactJs is for fornt using, but instead make an API call to a node js server, even the browser will block you from calling local commands

这篇关于如何从我的 react-app 启动节点脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆