sách gpt4 ăn đã đi

mysql - 使用 MySQl 的 NodeJs Restful Api

In lại Tác giả: Walker 123 更新时间:2023-12-01 00:34:56 25 4
mua khóa gpt4 giày nike

我已经通过 MongoDB 尝试过,但是我不能在 mongoDB 中使用 JOIN 查询,而且我的项目足够宽。所以,想在 MySQL 的 Node js 中创建 Restful API。谁能提出解决方案

câu trả lời hay nhất

要创建 REST API,您可以使用 express JS

var express = require('express');
var app = express();

app.get('/', function (req, res) {
//BELOW-CODE
});

您可以通过以下代码连接Mysql:

var mysql = require('mysql');

var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword",
database: "mydb"
});

con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM customers", function (err, result, fields) {
if (err) throw err;
console.log(result);
);
});

注意:安装 expressJS 框架以开始快乐编码:-)

关于mysql - 使用 MySQl 的 NodeJs Restful Api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55628224/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress