I'm trying to create a small hobby project to scrape real time stock prices using a simple NodeJS app.
I came across a couple of posts online saying Vercel would be a good platform to host a free tier and I was trying it out, but I keep seeing Not Found errors.
Would you guys know how to make this work? Will appreciate any help!
Folder structure:
├── api
│ └── index.ts
├── src
│ ├── api
│ │ └── router.ts
│ │ └── ...more_files
│ ├── config.ts
│ ├── scraper
│ │ └── script.ts
│ │ └── ...more_files
│ │ └── page.html (To render on one specific endpoint)
├── vercel.json
├── package.json
├── tsconfig.json
index.ts:
import express from "express";
import cors from "cors";
import * as CONFIG from "../src/config";
import { startUp, daily, dailyEx, quote, quoteEx } from "../src/scraper/script";
import cron from 'node-cron';
import bodyParser from 'body-parser';
import router from "../src/api/router";
const app = express();
app.use(bodyParser.json());
app.use(cors({ origin: "*" }));
app.use("/", router);
const HOST = CONFIG.HOST;
const PORT = parseInt(CONFIG.PORT);
const assets = startUp();
export const quoteArgs = quote.bind(null, assets);
cron.schedule(dailyEx, daily, {
timezone: 'Etc/UTC'
});
cron.schedule(quoteEx, quoteArgs, {
timezone: 'Etc/UTC'
});
export default app;
package.json:
{
"name": "stock-analyzer",
"version": "0.1.0",
"private": true,
"scripts": {
"clean": "rimraf build",
"build": "npm run clean && tsc",
"start": "npm run build && node build/api/index.js"
},
"dependencies": {
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"fs": "^0.0.1-security",
"h5wasm": "^0.7.5",
"node-cron": "^3.0.3",
"rimraf": "^5.0.8",
"serverless-http": "^3.2.0",
"yahoo-finance2": "^2.11.3"
},
"devDependencies": {
"@types/node": "20.14.10",
"typescript": "5.5.3"
}
}
tsconfig:
{
"compilerOptions": {
"lib": [
"es6"
],
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./build",
"rootDir": ".",
"experimentalDecorators": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": false
},
"include": [
"src/**/*.ts",
"api/**/*.ts"
]
}
vercel.json:
{
"version": 2,
"builds": [
{
"src": "build/api/index.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "build/api/index.js"
}
],
"buildCommand": "npm run build"
}
I've been stumped with what isn't working and tried a bunch of things.
This is the Vercel error I get, although there are no errors on deployment logs.