-1
I have a problem running my SQL.
When I run on localhost, my code is normal.
Follows code.
const express = require('express');
const fileUpload = require('express-fileupload');
const bodyParser = require('body-parser');
const mysql = require('mysql');
const path = require('path');
const app = express();
app.set('views', './views');
app.set('view engine','ejs');
const {getHomePage} = require('./routes/index.js');
const {addPlayerPage, addPlayer, deletePlayer, editPlayer, editPlayerPage} = require('./routes/player.js');
const port = 5000;
const db = mysql.createConnection ({
host: 'localhost',
user: 'root',
password: 'r00tpassword',
database: 'socka'
});
// connect to database
db.connect((err) => {
if (err) {
console.log("Não foi possivelse conectar ao mundo");
}
console.log('Connected to database');
});
global.db = db;
// configure middleware
app.set('port', process.env.port || port); // set express to use this port
app.set('views', __dirname + '/views'); // set express to look in this folder to render our view
app.set('view engine', 'ejs'); // configure template engine
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json()); // parse form data client
app.use(express.static(path.join(__dirname, 'public'))); // configure express to use public folder
app.use(fileUpload()); // configure fileupload
// routes for the app
app.get('/', getHomePage);
app.get('/add', addPlayerPage);
app.get('/edit/:id', editPlayerPage);
app.get('/delete/:id', deletePlayer);
app.post('/add', addPlayer);
app.post('/edit/:id', editPlayer);
// set the app to listen on the port
app.listen(port, () => {
console.log('Server running on port: ${port}');
});
Isso foi um app.js que eu peguei do
https://dev.to/achowba/build-a-simple-app-using-node-js-and-mysql-19me
para fazer um teste de servidor
e pelo visto, funcionou, mas quando eu acessava meu localhost:5000, me retornava isso
SyntaxError: Unexpected identifier in /Users/apple/Documents/NodeJS/views/index.ejs while compiling ejs
If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
Or, if you meant to create an async function, pass `async: true` as an option.
at new Function (<anonymous>)
at Template.compile (/Users/apple/Documents/NodeJS/node_modules/ejs/lib/ejs.js:626:12)
at Object.compile (/Users/apple/Documents/NodeJS/node_modules/ejs/lib/ejs.js:366:16)
at handleCache (/Users/apple/Documents/NodeJS/node_modules/ejs/lib/ejs.js:215:18)
at tryHandleCache (/Users/apple/Documents/NodeJS/node_modules/ejs/lib/ejs.js:254:16)
at View.exports.renderFile [as engine] (/Users/apple/Documents/NodeJS/node_modules/ejs/lib/ejs.js:459:10)
at View.render (/Users/apple/Documents/NodeJS/node_modules/express/lib/view.js:135:8)
at tryRender (/Users/apple/Documents/NodeJS/node_modules/express/lib/application.js:640:10)
at Function.render (/Users/apple/Documents/NodeJS/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/Users/apple/Documents/NodeJS/node_modules/express/lib/response.js:1012:7)
SyntaxError: Unexpected identifier in /Users/apple/Documents/NodeJS/views/index.ejs while compiling ejs
He returned me about 50 errors written the same thing.
If you want to know what mine was index.ejs
was exactly the same site.