有没有什么方法可以在这里用node而不是react.js来拉一个json文件

Is there any way I can pull a json file with node here instead of react.js?

本文关键字:js 文件 json 一个 react 方法 什么 在这里 node 有没有      更新时间:2023-09-26

我想使用json文件和node.js将商品添加到购物车中。我已经找到了使用react.js的教程,但我想知道是否可以使用node.js以及如何应用它?

https://github.com/scotch-io/react-flux-cart

express模块将处理来自客户端的请求。express帮助您接收json文件并将其发送到浏览器。

为了将购物车保存在服务器中,您必须使用数据库或文件存储。如mongodbmysql或简单地使用fs.writeFile

安装node并express(npm i express)后,这是一个向用户发送其购物车的JSON的代码示例:

app.get('/cart',function(req,res){
   res.send({total:250, items: [{name:'mybook',price:250}])
})

祝学习NodeJS好运。