1

I am trying to create a webapp from a template. This issue is that when I run the app, I am getting 'The page cannot be displayed because an internal server error has occurred'. I have done a bit of research and seem to be having issues with my node installation.

I have tried reinstalling npm, current version is 1.4.28. The error log shows:

0 info it worked if it ends with ok 1 verbose cli [ 'node', 1 verbose cli 'D:\Program Files (x86)\npm\1.4.28\node_modules\npm\bin\npm-cli.js', 1 verbose cli 'init' ] 2 info using [email protected] 3 info using [email protected] 4 error Error: EINVAL, invalid argument 4 error at new Socket (net.js:157:18) 4 error at process.stdin (node.js:693:19) 4 error at read (D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\read\lib\read.js:18:36) 4 error at PromZard.prompt (D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\init-package-json\node_modules\promzard\promzard.js:214:3) 4 error at PromZard.L (D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\init-package-json\node_modules\promzard\promzard.js:177:21) 4 error at PromZard.walk (D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\init-package-json\node_modules\promzard\promzard.js:146:5) 4 error at PromZard.loaded (D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\init-package-json\node_modules\promzard\promzard.js:90:8) 4 error at PromZard. (D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\init-package-json\node_modules\promzard\promzard.js:57:10) 4 error at fs.js:272:14 4 error at Object.oncomplete (fs.js:108:15) 5 error If you need help, you may report this entire log, 5 error including the npm and node versions, at: 5 error http://github.com/npm/npm/issues 6 error System Windows_NT 6.2.9200 7 error command "node" "D:\Program Files (x86)\npm\1.4.28\node_modules\npm\bin\npm-cli.js" "init" 8 error cwd D:\home\site\wwwroot 9 error node -v v0.10.40 10 error npm -v 1.4.28 11 error syscall uv_pipe_open 12 error code EINVAL 13 error errno 18 14 verbose exit [ 18, true ]

Here's what I have:

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')
});

Server.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);

I was initially getting the results from the server.js, but I have made a few changes to try and resolve the issue and how I am getting nothing. Is anyone able to pinpoint me to the issue?

Thanks

Edit: Adding the zip does this, creating another level of folder, and I am getting the message 'You do not have permission to view this directory or page.' when I try to run the app.

enter image description here

7
  • which template did you referred to? Commented Apr 16, 2019 at 5:39
  • github.com/jay3dec/NodeTaskApp The full tutorial is at codehandbook.org/web-app-using-node-js-and-mysql but I could never get the step run node app.js to work so I think I've got an issue. Commented Apr 16, 2019 at 7:19
  • The error is on your local env, right? Commented Apr 16, 2019 at 7:22
  • I am running the whole this in azure, not locally. portal.azure.com Commented Apr 16, 2019 at 7:23
  • Have you tried this locally? Commented Apr 16, 2019 at 7:26

1 Answer 1

2

You need to change

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

to app.listen(process.env.PORT);

The only way an azure webapp can be accessed via the internet is through the already-exposed HTTP (80) and HTTPS (443) TCP ports;

I have tested the project with your web.config and app.js. I will encounter the same error as yours.

enter image description here

After changing the listen port, it works well. You can refer to this article to deploy your nodejs app to azure. enter image description here

Sign up to request clarification or add additional context in comments.

8 Comments

This seems to be the answer, thank you! It seems like the node doesn't install properly in the cloud so if you do it locally it is fine. I just have one last thing tripping me up. When I followed the directions to upload to the cloud, it uploads the zip file into the root directory, and the app doesn't seem to like wwwroot/ZipFolderName... as the directory. It's looking for the sites files to be in the root folder. I am not sure if moving the files will break any of the links (or how to move files in the cloud), or if I need to modify the root directory in the app.js file.
@Kat When you upload the zip file to wwwroot directory, the zip file will be unzip, all your files are under wwwroot directory which is the root directory. You don't need to change anything to your app.js file.
@Kat If my answer is helpful for you, please make it as answer. Thank you.
Done, thanks for you help. I made an edit to the original post to show you what happens when I drag and drop the zip. It's unzipiing in a folder instead of in root. Am I doing something wrong?
@Kat You are welcome. The wwwroot directory is the root directory. The pages are in templates directory, right? app.get('/',function(req,res){ res.sendFile('home.html',{'root': __dirname + '/templates'}); }) This code has already done the route.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.