【问题标题】:NPM Errors in Node.js webappNode.js webapp 中的 NPM 错误
【发布时间】:2019-04-16 01:19:44
【问题描述】:

我正在尝试从模板创建 web 应用程序。这个问题是,当我运行应用程序时,我收到“由于发生内部服务器错误,无法显示页面”。我做了一些研究,似乎我的节点安装有问题。

我已经尝试重新安装 npm,当前版本是 1.4.28。错误日志显示:

0 信息如果它以 ok 结尾,它就会起作用 1个详细的cli ['节点', 1 详细的 cli 'D:\Program Files (x86)\npm\1.4.28\node_modules\npm\bin\npm-cli.js', 1 详细的 cli 'init' ] 2 使用 npm@1.4.28 的信息 3 使用 node@v0.10.40 的信息 4 错误 错误:EINVAL,无效参数 新 Socket 的 4 错误 (net.js:157:18) process.stdin (node.js:693:19) 出现 4 错误 4 读取错误(D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\read\lib\read.js:18:36) PromZard.prompt 出现 4 错误(D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\init-package-json\node_modules\promzard\promzard.js:214:3) PromZard.L 出现 4 错误(D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\init-package-json\node_modules\promzard\promzard.js:177:21) PromZard.walk 出现 4 错误(D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\init-package-json\node_modules\promzard\promzard.js:146:5) PromZard.loaded 4 错误 (D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\init-package-json\node_modules\promzard\promzard.js:90:8) PromZard 出现 4 个错误。 (D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\init-package-json\node_modules\promzard\promzard.js:57:10) fs.js:272:14 处出现 4 个错误 Object.oncomplete (fs.js:108:15) 出现 4 个错误 5 错误如果您需要帮助,您可以报告此整个日志, 5 错误,包括 npm 和节点版本,位于: 5 错误http://github.com/npm/npm/issues 6 错误系统 Windows_NT 6.2.9200 7 错误命令 "node" "D:\Program Files (x86)\npm\1.4.28\node_modules\npm\bin\npm-cli.js" "init" 8 错误 cwd D:\home\site\wwwroot 9 错误节点-v v0.10.40 10 错误 npm -v 1.4.28 11 错误系统调用 uv_pipe_open 12 错误代码 EINVAL 13 错误错误号 18 14 详细退出 [ 18, true ]

这是我所拥有的:

Web.config

<configuration>
    <system.webServer>

        <handlers>
            <!-- indicates that the app.js file is a node.js application to be handled by the iisnode module -->
            <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
        </handlers>

        <rewrite>
            <rules>
                <!-- Don't interfere with requests for logs -->
                <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^[a-zA-Z0-9_\-]+\.js\.logs\/\d+\.txt$" />
                </rule>

                <!-- Don't interfere with requests for node-inspector debugging -->
                <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">                    
                    <match url="^app.js\/debug[\/]?" />
                </rule>

                <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
                <rule name="StaticContent">
                    <action type="Rewrite" url="public{REQUEST_URI}" />
                </rule>

                <!-- All other URLs are mapped to the Node.js application entry point -->
                <rule name="DynamicContent">
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
                    </conditions>
                    <action type="Rewrite" url="app.js" />
                </rule>
            </rules>
        </rewrite>        
    </system.webServer>
</configuration>

App.js

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


app.use('/node_modules',  express.static(__dirname + '/node_modules'));
app.use('/style',  express.static(__dirname + '/style'));
app.use('/script',  express.static(__dirname + '/script'));

app.get('/',function(req,res){
    res.sendFile('home.html',{'root': __dirname + '/templates'});
})

app.get('/showSignInPage',function(req,res){
    res.sendFile('signin.html',{'root': __dirname + '/templates'});
})

app.get('/showSignUpPage',function(req,res){
  res.sendFile('signup.html',{'root':__dirname + '/templates'})
})

app.listen(3000,function(){
    console.log('Node server running @ http://localhost:3000')
});

服务器.js

var http = require('http');

http.createServer(function (req, res) {

    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.end('Hello, world!');

}).listen(process.env.PORT || 8080);

我最初是从 server.js 获得结果,但我进行了一些更改以尝试解决问题以及我如何一无所获。有人能指出我的问题吗?

谢谢

编辑:添加 zip 会执行此操作,创建另一个级别的文件夹,我收到消息“您无权查看此目录或页面。”当我尝试运行应用程序时。

【问题讨论】:

标签: node.js azure npm


【解决方案1】:

你需要改变

app.listen(3000,function(){
    console.log('Node server running @ http://localhost:3000')
});

app.listen(process.env.PORT);

通过 Internet 访问 azure webapp 的唯一方法是通过已经公开的 HTTP (80) 和 HTTPS (443) TCP 端口;

我已经使用您的 web.config 和 app.js 测试了该项目。我会遇到和你一样的错误。

更改监听端口后,效果很好。您可以参考此article 将您的 nodejs 应用程序部署到 azure。

【讨论】:

  • 这似乎是答案,谢谢!似乎该节点没有正确安装在云中,所以如果您在本地安装它就可以了。我只有最后一件事绊倒了我。当我按照指示上传到云端时,它会将 zip 文件上传到根目录,并且该应用程序似乎不像 wwwroot/ZipFolderName... 作为目录。它正在寻找位于根文件夹中的站点文件。我不确定移动文件是否会破坏任何链接(或如何在云中移动文件),或者我是否需要修改 app.js 文件中的根目录。
  • @Kat 当您将 zip 文件上传到 wwwroot 目录时,该 zip 文件将被解压缩,您的所有文件都在 wwwroot 目录下,即根目录。您无需对 app.js 文件进行任何更改。
  • @Kat 如果我的回答对您有帮助,请将其作为答案。谢谢。
  • 完成,感谢您的帮助。我对原始帖子进行了编辑,以向您展示拖放 zip 时会发生什么。它在文件夹中解压缩,而不是在根目录中。我做错了吗?
  • @Kat 欢迎您。 wwwroot 目录是根目录。这些页面在模板目录中,对吗? app.get('/',function(req,res){ res.sendFile('home.html',{'root': __dirname + '/templates'}); }) 这段代码已经完成了路由。
猜你喜欢
  • 1970-01-01
  • 2016-07-19
  • 2015-06-16
  • 2015-02-18
  • 2014-08-27
  • 1970-01-01
  • 2015-09-11
  • 2021-08-31
  • 2011-11-12
相关资源
最近更新 更多