I am trying to get a small webserive working with Express. My original code was throwing errors so I checked to see what could be wrong. I found out when I import things, it doesn't work. For example:
The use of require will work:
And yes, I have set "type": "module" in package.json and yes, I have restarted the server.
Could you possibly see where the problem might be?
import express from "express"
const app = express()
app.get('/', function (req, res) {
res.send('Hello World')
})
app.listen(80, async () => {
console.log(`Server ready at http://localhost:${80}`)
})
The use of require will work:
const express = require("express")
const app = express()
app.get('/', function (req, res) {
res.send('Hello World')
})
app.listen(80, async () => {
console.log(`Server ready at http://localhost:${80}`)
})
And yes, I have set "type": "module" in package.json and yes, I have restarted the server.
Could you possibly see where the problem might be?