Relooking at the repl link provided if you are wanting to do login and have a website and stuff it might be better for you to look into node.js and use express. I dont think you could really do a login with a simple html thing uless you call an external server.
You can do login information however there will be no "main" server for it so logging in will do nothing for them.
(If you switch to node.js there are more powerful ways to render html pages with custom user information, React.js, pug (different format doestn use <> but still lets you do html), handlebars, or e.js)
You can use MySQL with just plain js. However the database itself would have to be hosted externally from repl.it (you can not install mysql on repl.it)
The following is how you would do it using express
https://dev.to/achowba/build-a-simple-app-using-node-js-and-mysql-19me
And for what I think you are wanting to do you would want the session store for MySQLvar MySQLStore = require('express-mysql-session')(session);
const mysql = require("mysql");
https://www.npmjs.com/package/express-mysql-session
Quick example of some code.
const sessionoptions = {
//checkExpirationInterval: 1000 * 60 * 15,// 15 min // How frequently expired sessions will be cleared; milliseconds.
expiration: 1000 * 60 * 60 * 24 * 7,// 1 week // The maximum age of a valid session; milliseconds.
createDatabaseTable: true,// Whether or not to create the sessions database table, if one does not already exist.
schema: {
tableName: 'sessions',
columnNames: {
session_id: 'session_id',
expires: 'expires',
data: 'data'
}
}
};
const dbConnectionInfosession = {
multipleStatements: true,
connectionLimit : 10,
host: "localhost",
user: "root",
password: config.passwordDB,
database: "session"
}
const poolsession = mysql.createPool(dbConnectionInfosession);
const sessionStore = new MySQLStore(sessionoptions,poolsession);
app.use(session({
/*cookie: {
secure: true,
maxAge: 36000000 },*/
secret: secretRandom,
saveUninitialized: false,
resave: false,
store: sessionStore,
}));
Also side note from personal experince call the session store option first in your app chai. (app.use(sessionStore) -> app.use("someViewthing") -> app.get('/index'))
If you follow that
All code provided does work in a production enviorment.
two ways to fix this use
process.cwd()
or you can fix it via path
const path = require('path'); var __dirname = path.resolve();