I have a simple express app:
const express = require('express');
const { json } = require('express/lib/response');
const app = express()
const port = process.env.PORT || 3003
const path = require('path')
app.use(express.json());
app.get('/', (req, res) => {
console.log("Called!")
res.send('Welcome to Mini-Programs!')
})
app.get("/app", (req, res) => {
res.sendFile(path.join(__dirname, "./index.html"));
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
However, when I go to http://localhost:3003 I get nothing what mistakes am I making in this code?
CodePudding user response:
I just tried, your code works fine!
However you can remove const { json } = require('express/lib/response');
as you're not using it (you use express
import to call express.json()
which is fine).
Are you sure your server is starting on port 3003 ? You might be reading a different port from the $PORT
environment variable, so it's not defaulted to 3003 as it is on my machine.
CodePudding user response:
The issue is resolved and I did not change anything.
CodePudding user response:
Concellia
Ensure that you have node.js installed on your computer. If you have not yet installed Express, you need to do so. Use the node app.js command to run your app if your file name is app.js Your code works fine. A response is displayed at http://localhost:3003