欢迎来到码农权的博客 MaNongGeGe.|

Node.js express 连接数据库

Node.js express 连接数据库

  1. 下载包 express 与 mysql
  • yarn add express yarn add mysql
  const express = require('express');
  const mysql = require('mysql');
  const app = express();
  let db = mysql.createPool({
      host: '127.0.0.1',
      user: 'root',
      password: 'root',
      database: 'test'
  });
  db.query('select * from students', (err, result)=> {
      if(err) {
          return console.log(err.message);
      }
      console.log(result)
  })
  app.listen(8080, ()=> {
      console.log('http://127.0.0.1:8080');
  })

本文作者:HuangBingQuan

本文链接:https://www.cnblogs.com/bingquan1/p/16413281.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   HuangBingQuan  阅读(50)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 不将就 码农权
  2. 2 Bleeding Love 码农权
  3. 3 想你念你 码农权
Bleeding Love - 码农权
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

Not available