Simple login program in js

Hey guys do have any short and simple code for logins? What I’m used to doing is python so its still learning time for me in js.

If this is related to the same Repl in your other post, it’s not possible, not with plain JavaScript (you could potentially use a database like Firebase or MongoDB, I’m not sure if Mongo works with front-end JavaScript, but this would be insecure regardless). JavaScript is a front-end language, what you want for a login program is really a back-end/server-side language. You could use NodeJS for this.

The reason for this is that a front-end language has no way of making persistent changes to anything (for security reasons). In a case like this, you might use a front-end language to interact with the server, like a middle man between the user’s input and the server.

By creating a new Repl using the NodeJS template.

Just select the Node.js template, click ‘Create Repl’, and you’re good to go!
nodejs template
create-repl

how will I hook this up with my other Repl?

You could do that using requests, however it would be better to just move the files in the other one into a new NodeJS one.

I tried that but there’s no webviev

Yep, to get the webview, delete all the code in the index.js file and you should see some blue text talking about examples, click it. Then click the Express example.

k got it thanks! I will try that

1 Like

html does not seam to work. In the node.js

Do the below instead of app.get("index.html", /* etc */); and it should work:

app.get("/", function (req, res) {
	res.sendFile(__dirname + "/homepage/index.html");
});

Then using NodeJS, there are a number of different ways you could go about saving user information, you could use files (which one Replit is insecure since anyone can view the files in your Repl) or a database.

Here’s some stuff that might help you:

const Client = require("@replit/database");
const db = new Client();
// synchronous
await db.set("key", 123);
const value = await db.get("key");
console.log(value);
// asynchronous
let value = null;
db.set("key", 123).then(function() {
	db.get("key").then(function(val) {
		value = val;
		console.log(value);
	});
});

thanks for the suggestion!