Lipi Batra Lipi Batra - 4 months ago 5x
Node.js Question

How to include static html pages into my NodeJS project

I have a NodeJS project setup. I want to integrate my static html pages into it. Where can I do it ?

Thank you !


To expose static html, create a directory named "public" that lives next to your primary application file (app.js).

Assuming you are using the express framework, you can expose this directory by using the following code:

app.use(express.static(__dirname + "/public"));


var app = express();

Subsequently, any request to "/{something}" will attempt to resolve a route to a static file in your public directory, so if you had a file named {something} in that directory it would get served right up.