I have a folder with html files, a css file, and a javascript file along with images that I want to display in node.js. Is it possible to use all of that code already written and display that in a node.js app or would I have to recreate everything in node.js specifically? I've displayed the first html page, but the css and javascript I used does not work.
-
"display in nodejs" i guess you are new to node.js i would recommend to google for "express.js" and "ejs template engine" so set up an express server with ejs templateIlijanovic– Ilijanovic2019-10-24 18:33:29 +00:00Commented Oct 24, 2019 at 18:33
-
have a look at this: expressjs.com/en/starter/static-files.htmlmarzelin– marzelin2019-10-24 18:42:08 +00:00Commented Oct 24, 2019 at 18:42
Add a comment
|
1 Answer
The easiest way would be to use a framework like Express to serve your static files.
Here's how you would do something like this in express:
const express = require('express');
const app = express();
// Serves files in the public folder to the / route
app.use('/', express.static('public'));
// Use port 3000 for the server
app.listen(3000);
If your interested in doing it without Express (which I would not recommend) here is a example I found and a article as well.