質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Q&A

0回答

613閲覧

時間経つと接続切れてエラーがでる

退会済みユーザー

退会済みユーザー

総合スコア0

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

0グッド

0クリップ

投稿2022/08/08 20:02

編集2022/08/24 11:54

前提

node.js,heroku,mysqlの組み合わせでWEBアプリケーションを開発したのですが、テーブルプラスを閉じるとエラーが起きてしまいます。

実現したいこと

テーブルプラスを閉じてもエラーが起きないようにしたい。

発生している問題・エラーメッセージ

2022-08-08T12:23:07.942613+00:00 app[web.1]: TypeError: Cannot read properties of undefined (reading 'use') 2022-08-08T12:23:07.942613+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:1:5) 2022-08-08T12:23:07.942614+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14) 2022-08-08T12:23:07.942614+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) 2022-08-08T12:23:07.942614+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32) 2022-08-08T12:23:07.942614+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12) 2022-08-08T12:23:07.942615+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) 2022-08-08T12:23:07.942615+00:00 app[web.1]: at node:internal/main/run_main_module:17:47 2022-08-08T12:23:08.184088+00:00 heroku[web.1]: Process exited with status 1 2022-08-08T12:23:08.258647+00:00 heroku[web.1]: State changed from starting to crashed 2022-08-08T12:23:11.914771+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=kaimemo1993.herokuapp.com request_id=d03fa3ff-74cd-4a03-9374-03fa3dca7d3c fwd="133.32.129.34" dyno= connect= service= status=503 bytes= protocol=https 2022-08-08T12:24:38.601844+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=kaimemo1993.herokuapp.com request_id=3a336037-9c84-412d-adb9-d32cc03d9c22 fwd="133.32.129.34" dyno= connect= service= status=503 bytes= protocol=https 2022-08-08T12:31:25.000000+00:00 app[api]: Build started by user akiress55555@gmail.com 2022-08-08T12:31:40.000000+00:00 app[api]: Build succeeded 2022-08-08T12:31:40.451203+00:00 app[api]: Release v39 created by user akiress55555@gmail.com 2022-08-08T12:31:40.451203+00:00 app[api]: Deploy e3f458b8 by user akiress55555@gmail.com 2022-08-08T12:31:40.877111+00:00 heroku[web.1]: State changed from crashed to starting 2022-08-08T12:31:42.599609+00:00 heroku[web.1]: Starting process with command `npm start` 2022-08-08T12:31:43.786348+00:00 app[web.1]: 2022-08-08T12:31:43.786367+00:00 app[web.1]: > list-app@1.0.0 start 2022-08-08T12:31:43.786368+00:00 app[web.1]: > node app.js 2022-08-08T12:31:43.786368+00:00 app[web.1]: 2022-08-08T12:31:43.966409+00:00 app[web.1]: node:internal/modules/cjs/loader:936 2022-08-08T12:31:43.966410+00:00 app[web.1]: throw err; 2022-08-08T12:31:43.966410+00:00 app[web.1]: ^ 2022-08-08T12:31:43.966411+00:00 app[web.1]: 2022-08-08T12:31:43.966411+00:00 app[web.1]: Error: Cannot find module 'mysql2' 2022-08-08T12:31:43.966411+00:00 app[web.1]: Require stack: 2022-08-08T12:31:43.966412+00:00 app[web.1]: - /app/app.js 2022-08-08T12:31:43.966412+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) 2022-08-08T12:31:43.966413+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27) 2022-08-08T12:31:43.966413+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) 2022-08-08T12:31:43.966414+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18) 2022-08-08T12:31:43.966414+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:2:13) 2022-08-08T12:31:43.966415+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14) 2022-08-08T12:31:43.966415+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) 2022-08-08T12:31:43.966415+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32) 2022-08-08T12:31:43.966416+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12) 2022-08-08T12:31:43.966416+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) { 2022-08-08T12:31:43.966416+00:00 app[web.1]: code: 'MODULE_NOT_FOUND', 2022-08-08T12:31:43.966417+00:00 app[web.1]: requireStack: [ '/app/app.js' ] 2022-08-08T12:31:43.966417+00:00 app[web.1]: } 2022-08-08T12:31:44.091013+00:00 heroku[web.1]: Process exited with status 1 2022-08-08T12:31:44.282702+00:00 heroku[web.1]: State changed from starting to crashed 2022-08-08T12:31:44.287760+00:00 heroku[web.1]: State changed from crashed to starting 2022-08-08T12:31:46.171264+00:00 heroku[web.1]: Starting process with command `npm start` 2022-08-08T12:31:48.448104+00:00 app[web.1]: 2022-08-08T12:31:48.448122+00:00 app[web.1]: > list-app@1.0.0 start 2022-08-08T12:31:48.448123+00:00 app[web.1]: > node app.js 2022-08-08T12:31:48.448123+00:00 app[web.1]: 2022-08-08T12:31:48.702139+00:00 app[web.1]: node:internal/modules/cjs/loader:936 2022-08-08T12:31:48.708444+00:00 app[web.1]: throw err; 2022-08-08T12:31:48.708445+00:00 app[web.1]: ^ 2022-08-08T12:31:48.708445+00:00 app[web.1]:

該当のソースコード

var express = require('express'); var mysql = require('mysql2'); var app = express(); app.use(express.static('public')); app.use(express.urlencoded({extended: false})); var db_config = { host: '', user: '', password: '', database: '' }; app.get('/', (req, res) => { res.render('top.ejs'); }); app.get('/index', (req, res) => { connection.query( 'SELECT * FROM items', (error, results) => { res.render('index.ejs', {items: results}); } ); }); app.get('/new', (req, res) => { res.render('new.ejs'); }); app.post('/create', (req, res) => { connection.query( 'INSERT INTO items (name) VALUES (?)', [req.body.itemName], (error, results) => { res.redirect('/index'); } ); }); app.post('/delete/:id', (req, res) => { connection.query( 'DELETE FROM items WHERE id = ?', [req.params.id], (error,results) => { res.redirect('/index'); } ); }); app.get('/edit/:id', (req, res) => { connection.query( 'SELECT * FROM items WHERE id = ?', [req.params.id], (error, results) => { res.render('edit.ejs',{item:results[0]}); } ); }); app.post('/update/:id', (req, res) => { connection.query( 'UPDATE items SET name = ? WHERE id = ?', [req.body.itemName , req.params.id], (error, results) => { res.redirect('/index'); } ); }); app.set('port', (process.env.PORT || 5000)); var connection; function handleDisconnect() { console.log('INFO.CONNECTION_DB: '); connection = mysql.createConnection(db_config); connection.connect(function(err) { if (err) { console.log('ERROR.CONNECTION_DB: ', err); setTimeout(handleDisconnect, 1000); } }); connection.on('error', function(err) { console.log('ERROR.DB: ', err); if (err.code === 'PROTOCOL_CONNECTION_LOST') { console.log('ERROR.CONNECTION_LOST: ', err); handleDisconnect(); } else { throw err; } }); } handleDisconnect(); app.get('/', function(request, response) { connection.query('SELECT * FROM items WHERE id = ?', function(err, rows, fields){ if(err){ console.log('ERROR.SELECT_DB: ', err); throw err; } response.writeHead(200,{'Content-Type': 'text/plain'}); response.write(rows[0].message); response.end(); }); }); app.listen(app.get('port'), function() { console.log('heroku-mysql app is running on port', app.get('port')); }); app.listen(process.env.PORT || 3000);

試したこと

https://ninna2.hatenablog.com/entry/2017/02/22/node-mysql%E3%81%A7%E6%8E%A5%E7%B6%9A%E3%81%8C%E5%88%87%E3%82%8C%E3%82%8B%E7%82%B9%E3%82%92%E6%94%B9%E5%96%84
こちらのサイトのPROTOCOL_CONNECTION_LOSTの方を試してみたのですが、それでもエラーが出てしまいます。
ターミナルにてnpm install mysql2導入済み。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2022/08/08 22:36

>【再掲載】 質問は編集できますし、編集したり回答などがあればアクティブとして上がってくるので立て直す必要はないです。 むしろ削除依頼してたとしても未解決のまま同じ質問繰り返す方が印象良くないかと。
退会済みユーザー

退会済みユーザー

2022/08/09 00:35

どうせこの質問に助言しても削除申請するんだろうなって思えてしまって、他人の労力にありがたみを感じない人なんだろうなって印象がついてしまった
slemntqe

2022/08/09 02:34

過去の質問も「解決しました」とコメントしながらも感謝する気持ちは無く、質問も受付中のままになっていますね。あなたの利己的な性格が伺えます。回答する意思が削がれます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問