i have windows 10 wiht subsystem Linux (Ubuntu-20.04) and I am using WSL2. When I init frontend project (vue project) and I run npm run serve
then everything works fine. The application ran on localhost:8080 as i expect. But when i created backend for this app (new project with nodejs, express) I started simple server and in terminal looks fine but when i wanted to go in browser to localhost:5000 to see basic Hello World, the page is loading for a while and then says the webpage localhost didnt send any data.
Here is my app.ts
import express, { Application, Request, Response, NextFunction } from 'express'
import bodyParser from 'body-parser'
import cors from 'cors'
import 'reflect-metadata'
const app: Application = express()
const port = 5000
app.use(cors)
app.use(bodyParser.json({ limit: '20480kb' }))
app.get('/', (req, res) => {
res.send('Hello!')
})
const server = app.listen(port, 'localhost', () => console.log(`The server is running on port ${port}.`))
Here is my package.json scripts (compile typescript to javascript works fine):
"scripts": {
"start": "nodemon dist/app.js",
"build": "rm -rf dist/ && tsc -w",
"commit": "npx git-cz"
}
Here is my backend terminal, everything here works fine:
https://i.stack.imgur.com/pJIb9.png
I tried to use netstat to see connection:
https://i.stack.imgur.com/n5naM.png
My problem is that i cant reach the server on web browser, please help.