0

This is the code I have so far for my router. Just a basic GET request to the root of localhost:3000.

function fileSending(req, res) {
res.sendFile(__dirname + "/views/index.html");
};

app.get("/", fileSending);

I have also tried importing path and using the path.join method:

let express = require("express");
let path = require("path");
const app = express();

app.get("/", (req, res) => {
  res.sendFile(path.join(__dirname, "views", "index"))
});

module.exports = app;

update: Have also tried suggestions from another post. Still not seeming to render my html page on localhost. Getting this error:

ENOENT: no such file or directory, stat '/Users/loganaaron/Desktop/FreeCodeCamp/boilerplate-express/views/index'

My file structure relevant to this is as follows: |-- views | -- index.html |myApp.js (express route)

I have also tried:

app.get("/", (req, res) => {
  res.sendFile("views/index.html", { root: __dirname })
});

And:

app.get("/", (req,res) => {
  res.sendFile(path.resolve("/views/index.html"))
});
Community
  • 1
  • 1

0 Answers0