我正在尝试在服务器上部署一个非常简单的节点应用程序。我的服务器提供商允许使用节点激活目录。服务器提供商提供了一个示例,该示例可以工作,但是当我上传时却没有。为了简短起见,我将从示例开始: 它被称为 hello.js
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.end('<htnl><h1>Usama</h1></html>');
res.end('Hello, world!');
}).listen(process.env.PORT);
其中 config.web 文件包含以下内容:
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="hello.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="mysite">
<match url="/*" />
<action type="Rewrite" url="hello.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
它工作得很好。但是当我上传我的 node_modules 和我的文件并将 hello.js 的内容更改为以下内容时,我收到消息 404 file not found
const express=require('express')
const app=express()
app.get('',(req, res)=>{
res.send('Hello Express')
})
app.listen(process.env.PORT);
我无法弄清楚问题是什么。我的newnode目录的文件结构如下
iisnode(dir)
node-modules(dir)
hello.js
web.config
package.json
package-Lock.json
有人可以帮忙吗?