I want AWS EB to automatically build and run my files without me having to explicitly build everytime I push to git repo. I've tried placing this in "scripts" in package.json:
"start": "tsc build && node build/index.js"
The outDir specified in my tsconfig.json is build. This unfortunately didn't work and I get 'Degraded' health status. I know this is definitely the problem with my web server, because I tried manually building and placing node build/index.js in the "start" script, and it worked.
Here's my package.json:
{
"name": "woocommerce-api",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npx tsc && node build/index.js",
"dev": "nodemon -r dotenv/config src/index.ts",
"deploy": "npm run build && node build/index.js",
"build": "npx tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^18.7.18",
"cors": "^2.8.5",
"dotenv": "^16.0.2",
"express": "^4.18.1",
"helmet": "^6.0.0",
"nodemon": "^2.0.20"
},
"devDependencies": {
"@types/cors": "^2.8.12",
"@types/express": "^4.17.14",
"@types/helmet": "^4.0.0",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
"eslint": "^8.23.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.3"
}
}
And my simple app with a get path at home, and a post path at /hook to consume webhooks.
import express, { Response, Request } from "express";
import cors from "cors";
import helmet from "helmet";
const app = express();
app.use(cors());
app.use(helmet());
app.use(express.json());
const port = process.env.PORT || 8081;
app.get("/", (req: Request, res: Response) => {
res.send({ message: "Hello world1234" });
});
app.post("/hook", (req: Request, res: Response) => {
console.log(req.body);
res.status(200).send({ message: "success" });
});
app.listen(port, () => {
console.log(`Listening on port ${port}...`);
});
Would appreciate the help.