express.static()
returns a middleware function, and you have to tell your application to use it.
app.use(express.static(__dirname));
문제
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));