문제

I'm using expressJS framework. I get the JS load problem on browser console. Can you tell me what is the problem here?

var express    = require('express');
var fs    = require('fs');
var bodyParser = require('body-parser');

var app = express();

app.use(bodyParser());
express.static(__dirname);

app.get('/', function(req, res){
    fs.readFile('index.html', 'utf8', function(err, text){
        res.send(text);
    });
});

And this is how I include JS in index.html is

<script src="testscript.js"></script>

Folder structure is

- src
    - index.html
    - server.js
    - testscript.js
도움이 되었습니까?

해결책

express.static() returns a middleware function, and you have to tell your application to use it.

app.use(express.static(__dirname));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top