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

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

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

Ionicは、クロスプラットフォームに対応したモバイルアプリ開発のためのオープンソースUIフレームワークです。iOSやAndroid、Webのアプリケーションを1つのコードベースで開発できます。

MySQL

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

Node.js

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

Express

ExpressはNode.jsのWebアプリケーションフレームワークです。 マルチページを構築するための機能セットおよびハイブリッドのWebアプリケーションを提供します。

Q&A

1回答

436閲覧

Ionic 4のバックエンドのExpress.jsに出現するエラーが解決できない

dauto

総合スコア38

Ionic

Ionicは、クロスプラットフォームに対応したモバイルアプリ開発のためのオープンソースUIフレームワークです。iOSやAndroid、Webのアプリケーションを1つのコードベースで開発できます。

MySQL

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

Node.js

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

Express

ExpressはNode.jsのWebアプリケーションフレームワークです。 マルチページを構築するための機能セットおよびハイブリッドのWebアプリケーションを提供します。

0グッド

0クリップ

投稿2019/06/02 07:58

編集2022/12/21 14:12

techiediaries様のIonic 4のログイン処理の記事を参考にしながらIonic 4のログイン処理を設定していたのですが、Express.jsの認証サーバーでMySQLの設定中に以下のエラーが発生しました。
自分ではエラーの原因が分からなかったので、お手数ですがご助言を頂けると助かります。

index.js

1"use strict"; 2const express = require('express'); 3const bodyParser = require('body-parser'); 4const cors = require('cors') 5const mysql = require('mysql'); 6const connection = mysql.createConnection({ 7 host: 'XXX.XXX.XXX.XXX', 8 port: 3306, 9 user: '', 10 password: '', 11 database: 'eccube_db_2' 12}); 13const jwt = require('jsonwebtoken'); 14const bcrypt = require('bcryptjs'); 15const crypto = require("crypto"); 16 17const SECRET_KEY = "secretkey23456"; 18 19const app = express(); 20const router = express.Router(); 21app.use(cors()) 22 23connection.connect() 24 25router.use(bodyParser.urlencoded({ extended: false })); 26router.use(bodyParser.json()); 27} 28const findUserByEmail = connection.query('SELECT * FROM 'dtb_customer' WHERE 'email' = ?', [email], function (err, row, fields) { 29}); 30 31router.get('/', (req, res) => { 32 res.status(200).send('This is an authentication server'); 33}); 34 35router.post('/login', (req, res) => { 36 const email = req.body.email; 37 const default_password = req.body.password; 38 const hmac = crypto.createHmac('sha256', 'NFXwzxb5o9hfELny04AaoY0SgLRHrJlc'); 39 hmac.update(default_password . ':' . req.body.hash) 40 findUserByEmail(email, (err, user)=>{ 41 if (err) return res.status(500).send('Server error!'); 42 if (!user) return res.status(404).send('User not found!'); 43 const result = bcrypt.compareSync(password, user.password); 44 if(!result) return res.status(401).send('Password not valid!'); 45 46 const expiresIn = 24 * 60 * 60; 47 const accessToken = jwt.sign({ id: user.id }, SECRET_KEY, { 48 expiresIn: expiresIn 49 }); 50 res.status(200).send({ "user": user, "access_token": accessToken, "expires_in": expiresIn}); 51 }); 52}); 53 54app.use(router); 55const port = process.env.PORT || 3000; 56const server = app.listen(port, () => { 57 console.log('Server listening at http:fuwarun.net'); 58}); 59 60connection.end()
const findUserByEmail = connection.query('SELECT * FROM 'dtb_customer' WHERE 'email' = ?', [email], function (err, row, fields) { ^^^^^ SyntaxError: Unexpected token const at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:549:28) at Object.Module._extensions..js (module.js:586:10) at Module.load (module.js:494:32) at tryModuleLoad (module.js:453:12) at Function.Module._load (module.js:445:3) at Module.runMain (module.js:611:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:160:9)

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

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

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

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

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

guest

回答1

0

router.use(bodyParser.urlencoded({ extended: false }));

router.use(bodyParser.json());
}

ここに余計な }が入っているのが原因かもしれないです。

ご確認お願いします。

投稿2019/06/02 14:43

編集2019/06/02 16:39
tail12

総合スコア607

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問