I m new in typescript and node and i tried to render a html in javascript with typescript.
My index.ts (The application)
import express from 'express';
const AWS = require("aws-sdk");
AWS.config.update({ region: "us-east-1" });
const app: express.Application = express();
const bodyParser = require('body-parser');
const port = 3000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }))
app.use(express.urlencoded({ extended: true }))
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res) {
res.sendFile("../public/index.html")
});
How can i tell javascript to render the HTML in the public folder and not dist folder.
The structure of the code:
THe package.json:
{
"name": "villa",
"version": "1.0.0",
"description": "This README would normally document whatever steps are necessary to get your application up and running.",
"main": "dist/index.js",
"scripts": {
"start": "ts-node src/index.ts",
"build": "tsc",
"serve": "node dist/index.js",
"postbuild": "chmod +x bin/postbuild.sh && ./bin/postbuild.sh"
},
"repository": {
"type": "git",
"url": "git+https://emoleumassi:[email protected]/kazikamerun/villa.git"
},
"author": "Emo Leumassi",
"license": "ISC",
"bugs": {
"url": "https://bitbucket.org/kazikamerun/villa/issues"
},
"homepage": "https://bitbucket.org/kazikamerun/villa#readme",
"dependencies": {
"@types/express": "^4.17.21",
"@types/node": "^20.14.2",
"aws-sdk": "^2.1620.0",
"body-parser": "^1.20.2",
"express": "^4.19.2",
"html": "^1.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
}
After ran npm run build
and npm run serve
, i got an error, when i called a localhost:3000
:
Error: ENOENT: no such file or directory, stat '/Users/emoleumassi/Documents/Projects/villa/dist../public/index.html'