2016-12-26 85 views
0

我main.js我的Express服务器文件需要使用express.static()

var express = require('express'); 
var app = new express(); 

app.get('/', function(req,res){ 
    res.render('./../app/index.ejs', {}); 
}) 
.use(express.static(__dirname + '../app')) 
.listen('3000'); 

我做.use(express.static(__dirname + '../app')) to ask express to make it static

但我仍然有错误的没有发现GET http://localhost:9001/main.jsx 404 (Not Found)

文件未找到我的index.ejs文件看起来像这样

<head> 
    <script src="./main.jsx"></script> 
</head> 
<body>Hello</body> 

怎么了?

回答

1

解决的路径是不正确的

应该

.use(express.static(__dirname + '/../app'))