Azure expressjs web apps - node.js

I have created an express application in Visual Studio. I am having problems running it in azure once I've hosted.
It does not seem to find my node_modules folder.
Whenever I deploy and visit the site, on Kudu under the /logStream url I receive the error
cannot find module 'debug'
I found out that the debug module was required in the www folder. I then removed it from there and redeployed.
After redeployment I get
cannot find module 'express'
When I run my app in production (locally), I do not experience these problems.
One suggestion was removing the node_modules folder and then publish to Azure, with that you then use npm install on Kudu powershell or cmd. I have tried this and the same errors still come back. Could you please direct me on how I can resolve this?
package.json:
{
"name":"app-name",
"version":"0.0.0",
"private":true,
"scripts":{
"start":"node ./bin/www"
},
"description":"descrt",
"author":{
"name":"myname",
"email":"myemail#smtpserver.com"
},
"dependencies":{
"body-parser":"~1.8.1",
"cookie-parser":"~1.3.3",
"debug":"~2.0.0",
"express":"~4.9.0",
"jade":"~1.6.0",
"morgan":"~1.3.0",
"request":"^2.72.0",
"serve-favicon":"~2.1.3",
"stylus":"0.42.3"
}
}

Related

How to use Node -r flag inside npm scripts on Azure App Service

I am running a node site on an Azure App Service but it won't start with the following line in my package.json scripts.
"scripts": {
...
"serve": "node -r dotenv-azure/config dist/server.js",
...
},
The -r flag is required to preload environment variables using dotenv-azure, as per their own instructions... https://www.npmjs.com/package/dotenv-azure
it works absolutely fine on localhost (Windows), it loads the config before starting the server. On Azure App service (windows) however it fails to start the server and I get a 503 error after starting it.
I have tried switching on application logging but because it can't even start the server I get nothing in the logs.
After add httpplatformhandler in web.config file, it works for me. You can download my sample code from github. You will find my web.config file.
Test Steps:
1. Create a sample code.
2. Create .env file.
3. Test result in local.
4. Deploy by git.
After deployed, it also has some error, we should add web.config to solve it.
After add web.config file ( With httpplatformhandler):

deploying es2015 nodejs site to azure

I am building a site with node.js express
and this is my file structure:
local file structure
the dist folder holds the packed version of the site and the src the dev
also I have 2 server file once for each version.
I went with that style after doing a pluralsight course with the same style.
my npm start script is:
"scripts": {
"start": "node node_modules/babel-cli/bin/babel-node.js tools/distServer.
},
locally it works great.
I hooked my azure webapp to my github repo for this project and each time it tells me the the build was successfully even that at first it looked for a server.js file at the root, I added it later as a copy of the distServer file.
and then I noticed another error:
"Start script "./node_modules/babel-cli/bin/babel-node.js server.js" from package.json is not found."
as the built was successful I didn't pay too much attention to it, but when I try to access the site it returns only 500 errors
once I checked the logs they were full of:
import express from 'express';
^^^^^^
SyntaxError: Unexpected token import
I have no idea how to make it work on azure, like it does locally and would appreciate any help.
It seems like your local node js version does not match you node js version on azure .
Compare your node js version by doing (node -v or nodejs -v ) on both environnement .

Running blockchain-wallet-service on a Heroku worker

I'm trying to deploy my Django app on Heroku, that makes use of the Blockchain.info API V2 (https://github.com/blockchain/service-my-wallet-v3) and thus needs to run blockchain-wallet-service in the background, which in turn needs Node.js and npm installed.
On localhost, I have used this API successfully by running the service on my own machine, but I'm having trouble deploying to Heroku. Firstly, I assume I will need to run the service on a separate dyno, and that I will need node and npm installed on my instance.
Can someone tell me how to achieve this? I'm new to more advanced features of Heroku, I've tried to use the nodejs buildpack but I doubt this is the correct way. There is also this: https://elements.heroku.com/buttons/kmhouk/service-my-wallet-v3 which I've deployed as a separate app but I've failed to merge it in some way to my Django app.
Any help is much appreciated!
I had this exact same issue, bro, and i finally got some light in the end of the tunnel.
I've cloned the https://github.com/blockchain/service-my-wallet-v3 repository and deployed it to heroku and made some changes on "package.json" file. The problem is that (in heroku) you need to declare the dependencies on package file. I've added these lines:
"dependencies": {
"blockchain-wallet-service": "~0.22.4",
}
and a script to test in the deploy:
"scripts": {
"postinstall": "blockchain-wallet-service -V"
}
Also, by cloning this repository, i needed to add this line too:
"license" : "(ISC OR GPL-3.0)",
hope it works for you

Azure: "You do not have permission to view this directory or page

I have created a node.js application in Visual Studio 2015 using the Azure SDK 2.7 and the Node.js Tools.
I have successfully set up CI with BitBucket in my web app and I can see that changes to the repository do indeed trigger a build and deploy.
However, the page I reach (http://ftct.azurewebsites.net/) complains: You do not have permission to view this directory or page.
I have specified a default file (kinda) in my node.js by using: app.get('/', routes.index);
So trying to navigate directly to this file, http://ftct.azurewebsites.net/signin.html, yields a different error: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
I configured the app to run on port 1337 in Visual Studio, but using this port doesn't overcome the problem. Trying to navigate to a ported address yields a timeout.
Any ideas?
I had the same issue,
you need web.config, package.json, server.js at the root
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="server.js" verb="*" modules="iisnode" />
</handlers>
</system.webServer>
</configuration>
in package.json you need to have:
...
"scripts": {
"start": "node server"
},
...
and in your server.js make sure that you set the server port number to
process.env.PORT || 1337;
Edit: Try creating "Node JS Empty Web App" from the gallery at https://portal.azure.com and compare the web.config and the site with what you have. It's possible that you're missing some config settings.
Previous answer: first off, only ports 80 and 443 are available in Azure Web Apps (the new name of Azure Websites). So port 1337 will not work. Reconfigure your app to run on port 80 or 443. Regarding the permission issue, do you have App Service Authentication enabled? Make sure that is disabled, by editing the Web App's application settings as below.
You can try to create a instance of "Node JS Empty Web App" from the Gallery at the old portal http://manage.windowsazure.com, see below.
Then, doing the set up deployment from source control at the quick glance of the web app dashboard page to deploy your web app.
Now, browse the web app http://<app-name>.azurewebsites.net that works fine.
You're probably missing the web.config file which is required if iisnode is used to run node processes behind iis or iis express.
https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
In my case, I got this error when using ZipDeploy: please be sure to compress files within the root folder, so that the Node.js files could be listed on Kudu at the a base level, instead of one folder more. Thanks to mike-urnun-msft.
Also when you deploy the zip file via the azurewebsites.net/ZipDeployUI, make sure that you see the files being unzipped on the /wwwroot level.
If the files show up under /wwwroot/your-app-folder/ you may get this permission issue. I took a long time to figure this out! Hope it helps.
My situation is similar but slightly different. I was working on the Facebook Messenger Platform "Setting Up Your Webhook" documentation steps.
localhost was working just fine, but upon deployment, it would simply say what others have noted.
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
my final package.json looked like it, and it worked.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
I think, the issue boils down to the way facebook provided the demo code. The demo code simply does not have everything needed to deploy specifically on azure.
I have put my final code here (it can be used as a starter i think for another person who is running into deployment issues).
Also, interestingly enough, others have suggested web.config, but I did not need it really.
https://github.com/Jay-study-nildana/FBMessengerWebHook
The problem is most likely the wrong folder was pushed up. For an ASP.NET server the root folder must have the index.html file.
Angular Specific
Before deploying issue ng build --prod in your dev environment.
This creates a 'dist' folder in the solution.
Next open Visual Studio Code to the first folder in the 'dist' folder.
In this case the folder name was 'resume' which just so happened to be the Angular project name. Note that the index.html file is in this folder.
Note you know you are on the right track when pushing this up because this folder is small and it finishes quickly.
I use the Azure tools plugin for VSCode, it simply prompts me for the proper subscription (your Microsoft account) and from there just click the up arrow for the upload!

How to initialize a koa node.js app application on IISNode (Azure WebSites)

We are currently moving a self-hosted koa app to IISNode on Azure WebSites..
In self-hosting, we initiallize the application by calling
node --harmony ./bin/application
Requests then go to ./index.js.
However we could not find how to setup IISNode to call "bin/application" at initialization time.
Any ideas?
Thanks
Not sure this is the same scenario, but I ran into something that sounds like this when express.js started using ./bin/www as the entry point for express.js apps. Initially it broke everything, but now we look for the "scripts" entry in the package.json to tell Azure how to configure IISNode for the application. For express, it generates a "scripts" entry that looks like this:
"scripts": {
"start": "node ./bin/www"
},
When Azure sees this, it generates a web.config on the server that uses ./bin/www for the entry point.
So... I'd say first off, try adding a "scripts" entry to the package.json that points to your ./bin/application file, and try deploying that to Azure. Hopefully that 'just works'. If it doesn't, try adding a web.config to the root of your application, using https://gist.github.com/Blackmist/8677359708fd30779c77 as the contents. This should point IISNode to the ./bin/application file as the entrypoint, and is what Azure Websites should automatically generate when it sees the "scripts" entry in the package.json file.
The other problem you'll run into is using Node.js v0.11.13, which I don't believe is included in Azure websites by default, and passing the --harmony switches. http://azure.microsoft.com/en-us/documentation/articles/nodejs-specify-node-version-azure-apps/ has a section on including a version of node.js as part of your website. In the iisnode.yml file, you'd want to have a line similar to the following:
nodeProcessCommandLine: d:\home\site\wwwroot\bin\node.exe --harmony
I believe this should make this work.
You can setup custom deployment scripts for Azure Websites.
This blog post contains details on how to use it:
http://blog.amitapple.com/post/38417491924/azurewebsitecustomdeploymentpart1/#.VBcrnPldXIc

Resources