nodejsmysqlconnectiontutorial
2017-01-30 00:40
471 查看
mkdir nodejsmysqlconnectiontutorial
974 cd nodejsmysqlconnectiontutorial/
975 npm init
976 npm install –save express@latest mysql@latest
vi script.js
974 cd nodejsmysqlconnectiontutorial/
975 npm init
976 npm install –save express@latest mysql@latest
vi script.js
var express = require('express'); var mysql = require('mysql'); var app = express(); // var connection = mysql.createConnection({ var connection = mysql.createPool({ // properties.. connectiononLimit:50, host:'localhost', user:'root', password:'611', database:'products' }); // connection.connect(function(error){ // //callback // if(!!error){ // console.log('error'); // } else{ // console.log('connected'); // } // }); app.get('/',function(req,res){ // //about mysql // connection.query("select * from users",function(error,rows,fields){ // // callback // if(!!error){ // console.log('error in the query'); // } else{ // console.log('successfull in the query'); // console.log(rows[0].email); // res.send('hello'+ rows[0].email); // // res.send({rows}); // } connection.getConnection(function(error,tempCount){ if(!!error){ tempCount.release(); console.log('Error'); }else{ console.log('connected!'); tempCount.query('select * from users',function(error,rows,fields){ tempCount.release(); if(!!error){ console.log('error in the query'); } else{ res.json(rows); // res.send('hello'+ rows[0].email); } }); } }); }) app.listen(1337);
相关文章推荐
- node.js如何读取MySQL数据
- Node.js调用mysql的存储过程
- [Node.js]expressjs简单测试连接mysql
- nodejs + redis/mysql 连接池问题
- nodejs mysql pool 只能插入10条记录或者较少记录
- Share a tutorial about Node.js
- Node.js Async Tutorial
- APNs功能之Node.js和Mysql应用总结
- Node.js 连接 MySQL 并进行数据库操作
- node.js 开发指南 – Node.js 连接 MySQL 并进行数据库操作
- node.js基于工厂方法的mysql模块封装
- 安装node.js,CoffeeScript,Express.js,mysql,jade
- Build a JavaScript Compressor tool using NodeJS, ExpressJS, Jade, UglifyJS tutorial Read more: http
- node.js使用mysql模块的坑
- Node.js,Express,Mysql小结1
- node.js如何读取MySQL数据(转)
- node.js的generic-pool与mysql结合,mysql连接池
- Node.js开发指南中的简单实例(mysql版)
- node.js连接MySQL
- node.js :net.Server connection 事件 与 net.Socket conntct事件 触发顺序。