日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

nodejs实现的简单接口

發布時間:2025/4/9 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nodejs实现的简单接口 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
var http = require('http'); var mysql = require('mysql'); var connection = mysql.createConnection({host : 'rm-bp1w72suk8pc5h6mk.mysql.rds.aliyuncs.com',user : 'r85u40z94p',password : 'Mafeng11',database: 'r85u40z94p' }); //開始你的mysql連接 connection.connect();var server = http.createServer(function (req, res) {//如果你發一個GET到http://127.0.0.1:9000/testvar url_info = require('url').parse(req.url, true);//檢查是不是給/test的requestif(url_info.pathname === '/test'){res.writeHead(200, {'Content-Type': 'text/plain'});connection.query('SELECT * FROM `r85u40z94p`.`user` order by rand() LIMIT 5',function(err,rows,fields){//處理你的結果// res.end(rows.constructor);// 輸出結果 res.end(JSON.stringify(rows));console.log(rows.constructor);console.log(typeof(rows));res.end(rows.join);console.log(err);console.log(fields);});}//這個是用來回復上面那個post的,顯示post的數據以表示成功了。你要是有別的目標,自然不需要這一段。else{req.pipe(res);} }); server.listen(9000, '127.0.0.1'); //在server關閉的時候也關閉mysql連接 server.on('close',function(){connection.end(); }); console.log('listening on port 9000');

?

轉載于:https://www.cnblogs.com/mafeng/p/6106893.html

總結

以上是生活随笔為你收集整理的nodejs实现的简单接口的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。