0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Node.jsでDatabaseに接続する

Posted at

MySQLをインストールする

npm install mysql

app.jsにmysqlをimportする

app.js
const mysql = require('mysql');

Databaseに接続する

app.js
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'progate',
  password: 'password',
  database: 'list_app'
});

connection.query(A, B)
第一引数 A はクエリ
第一引数 B は関数の処理内容

jsファイルからクエリを流す

app.js
  connection.query(
    //クエリ
    'SELECT * from items',
    //function
    (error, results) => {
      console.log(results);
      res.render('index.ejs');
    }
  );
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?