Answer the question
In order to leave comments, you need to log in
I need to include static files on node js, what should I do?
server.js:
const path = require('path');
const express = require('express');
const app = express();
const server = require("http").createServer(app);
const io = require("socket.io").listen(server);
app.use('/dist', express.static('dist'));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});
server.listen(3000, () => {
console.log('Server started!');
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Document</title>
<link href="main.fa66f4cb4759dd0c1a34.css" rel="stylesheet"></head>
<body>
<h1>Hello World!</h1>
<script src="main.js"></script></body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question