Whats the way glitch starts html code?

Cannot GET / when i try localhost, here is the code I think its erroring on.

**const express = require(“express”);

const app = express();

app.get("/index.html", (request, response) => {

response.json("/index.html")

});

app.listen(process.env.PORT);

const listener = app.listen(process.env.PORT, () => {

console.log("Your app is listening on port " + listener.address().port);

});

console.log(“started”);**

thats all i have in my script.js.

how would i fix this? @RiversideRocks

In that case, visit index.html

response.json("/index.html")?

What are you asking? You should also not use index.html in Express routing, you should use /

but then it says it cant find it?

Hello @mynamecolt420, what you need is an application to serve your static files over the internet, or your local network.

In almost every programming language there is a way to do that, however the one I find easiest is using Node.js and Express. After installing node you can open up a shell (command prompt or terminal), I suggest you navigate to a testing directory.

When you have a directory set for this you can start by executing the following commands:

npm init -y # Initiate a new project or package.
npm i -S express # Save express as one of your dependencies.

After that you can open up your preffered text editor and create a file called index.js inside of that directory and write the following code:

// Fetch dependencies.
const Express = require("express");

// Create an express application.
const App = Express();

// Use a static site middleware provided by express.
App.use(Express.static(__dirname + "/public"));

// Start the web server.
App.listen(process.env.PORT || 3000, () => console.log("🚀 The server is listening on http://127.0.0.1:3000"));

Now create a file located in path/to/dir/public/index.html

<html>
  <head>
    <meta charset="utf-8" />
    <title>My Static Webpage</title>
  </head>
  <body>
    <h1>Hello world</h1>
  </body>
</html>

The you run your app by running the following command node . inside of the directory.

1 Like

It is node . or node yourservername.js.

Thanks for clearing up the small confused mess of answers! :slightly_smiling_face::stuck_out_tongue_closed_eyes:

3 Likes