Lipi Batra
Lipi Batra

Reputation: 9

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 !

Upvotes: 0

Views: 86

Answers (1)

Hamilton Lucas
Hamilton Lucas

Reputation: 419

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"));

where

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.

Upvotes: 1

Related Questions