I cannot figure out what's breaking this code when changing to ES6. I get this error when hitting the home route (or any other that requires rendering): Error: Failed to lookup view "index.html" in views directory "/Users/someguy/Documents/project/src/views".
This works fine in Common JS:
const express = require('express')
const path = require('path')
const dotenv = require('dotenv')
const ejs = require('ejs')
dotenv.config()
const app = express()
const PORT = process.env.PORT || 5000
app.set('port', PORT);
app.set('view engine', 'ejs')
app.engine('html', ejs.renderFile)
app.set('views', path.join(__dirname, 'views'))
app.get('/', (req, res) => {res.render('index.html')})
app.use(express.static(path.join(__dirname, '/public')));
app.use(express.static(path.join(__dirname, '/scripts')));
app.listen(PORT, console.log(`Server running in ${process.env.NODE_ENV} mode in port ${process.env.PORT}`))
This is the only thing that changes in my ES6 version:
import express from 'express'
import dotenv from 'dotenv'
import ejs from 'ejs'
import path from 'path'
const __dirname = path.dirname(new URL(import.meta.url).pathname);
What could be the problem?