Skip to content

Instantly share code, notes, and snippets.



Created Nov 13, 2016
What would you like to do?
Express server with static files support
import * as express from "express";
import { Request, Response, NextFunction } from "express";
import * as bodyParser from "body-parser";
import * as path from "path";
import { productsRouter } from "./routes/products";
namespace express_router {
let app = express();
let staticRoot = path.join(__dirname, "../");
let scripts = path.join(__dirname, "../../node_modules");
let port: number = process.env.PORT || 3000;
// Server static files
app.use("/node_modules", express.static(scripts));
// Plug in body parser middleware for posting JSON
// Add products router
app.use("/api/products", productsRouter);
app.listen(port, () => {
console.log(`Simple Express Web API listening on port ${port}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment