Question:
How do i get node.js to work in an html project? I have been trying to get node.js to work in html for a few days now and nothing seems to work (that ive found). I found this project on another old replit ask but i cant figure out how @Coder100 did it:
const { MongoClient, ServerApiVersion } = require('mongodb');
const uri = "mongodb+srv://test:CeznoqFJJZSx9e5h@cluster0.9kxt3qm.mongodb.net/?retryWrites=true&w=majority";
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
const client = new MongoClient(uri, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
}
});
async function run() {
try {
// Connect the client to the server (optional starting in v4.7)
await client.connect();
// Send a ping to confirm a successful connection
await client.db("admin").command({ ping: 1 });
console.log("Pinged your deployment. You successfully connected to MongoDB!");
} finally {
// Ensures that the client will close when you finish/error
await client.close();
}
}
run().catch(console.dir);
I am confused what you mean by making NodeJS in HTML. You use NodeJS to make a server to host HTML. You can use HTML in NodeJS but not NodeJS in HTML. Also AFAIK you cannot use NodeJS on an HTML/CSS/JS Repl template because those templates are special. Luckily you used the NodeJS template. Can you please rephrase your question?
and then put in the Node.js you need, put in the HTML and run the repl. A regular HTML/CSS/JS repl can’t run Nodejs at all, it has no server.
Edit: the javascript alone won’t be enough btw you need to start a server with Express, https://expressjs.com/, and modify the code to host the website
A bug with Replit, crashloops are common and usually happen when you’re trying to stop a Repl, while the client/service is still trying to run the Repl.