Hosting a nodejs express site on Windows Azure - node.js

I created a new NodeJS site based on the documentation of Durandal. It works locally. I set up Windows Azure to pull in the changes of my GitHub repository, which it does correctly.
However, (after enabling errors) I'm getting the an internal server error.
I checked my FTP for the logs, but don't have any. There is a 'Git' folder, but nothing interesting there.
When I change my server.js file to the hello world sample, everything works:
var http = require('http')
var port = process.env.PORT || 1337;
http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(port);
This is my server.js now:
var express = require('express'),
routes = require('./routes'),
engines = require('consolidate');
exports.startServer = function(config, callback) {
var port = process.env.PORT || config.server.port || 1337;
var app = express();
var server = app.listen(port, function() {
console.log("Express server listening on port %d in %s mode", server.address().port, app.settings.env);
});
app.configure(function() {
app.set('port', port);
app.set('views', config.server.views.path);
app.engine(config.server.views.extension, engines[config.server.views.compileWith]);
app.set('view engine', config.server.views.extension);
app.use(express.favicon());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.compress());
app.use(config.server.base, app.router);
app.use(express.static(config.watch.compiledDir));
});
app.configure('development', function() {
app.use(express.errorHandler());
});
app.get('/', routes.index(config));
callback(server);
};
So, has anyone succesfully hosted an Express (or more specifically, the Durandal skeleton for Mimosa) NodeJS site on Windows Azure? Or do you know how or where I can find the internal server error?

I've launched a few express applications on the Windows Azure platform and found that I had several instances of it failing quite silently. I personally have found the approach suggested in this post by Jay Harris really helpful as it allows me to import dependencies (npm, bower or other) and run grunt tasks to compile the project etc.
A few things worth noting is that often after a new deploy the updates did not display until restarting the Azure server in the control panel. Sometimes the deploy scripts timed out and I had to check them regularly.
This doesn't exactly answer what's wrong with your code (sorry) but I've posted an example using the method mentioned above that may help. The main deploy files are 'web.config', 'deploy.sh' and '.deployment' as well as your 'package.json' file.

Related

Failed to run Sencha CMD generated ExtJS 6.2 app on Node js

I am trying to run my existing ExtJS 6.2 app generated using Sencha CMD on Node.js. Below is my app.js:
const express = require('express');
const app = express();
//Middleware
app.use(express.static(__dirname + '/public/monitor/' ));
app.post('/', function( req ,res){
res.send("Success");
});
app.listen(3000, function(){
console.log('Server running on port 3000');
});
var server = app.listen(3300, function () {
var host = server.address().address;
var port = server.address().port;
console.log('App listening at http://%s:%s', host, port);
});
However, it is not able to run the page due to the following error.
Refused to apply style from 'http://localhost:3000/build/development/Monitor/classic/resources/Monitor-all_1.css?_dc=1597650810261' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
There is already a guide in sencha website but that is not for GPL version of ExtJS. So I cannot update to ExtJS 6.6 or 7.0.
Is there any work around for this?
The issue was caused because the css file was missing in the folder. I got it from another machine and it fixed the problem.

Make node.js run on codetasty

I am coding on codetasty and wanting to run a nodejs file that works on localhost. I am using the sandbox on codetasty so the link is similar to https://'s.codetasty.com'/My username/mysandbox/project/.
var app = express();
var serv = require('http').Server(app);
app.get('/',function(req, res) {
res.sendFile(__dirname + '/client/index.html');
});
app.use('/client',express.static(__dirname + '/client'));
serv.listen(2000);
console.log("Server started.");
When I direct to my index.html file https://'s.codetasty.com'/My username/mysandbox/project/client/index.html only the hmtl "runs" but none of the nodejs is running (on local host you would just do node 'filename'.js in console)
Node (and other server-side projects) don't work on Sandbox workspaces.
Sandbox workspaces are only for front-end coding.

Say 'Hello World!' in Openshift with Node.js

I created an app in Openshift and created a local git repo on my computer. I want to change the default welcome page here: http://nodejs-j4nos.rhcloud.com:3000 and just tell Hello world as this tutorial say.
So I removed from local repo the index.html, and modified server.js, pasted in this code below. And commit, and push. I get a long approval, that they accepted my commit.
If I good understand I do not have to stop node and start it again, but Openshift do it for me. But as you can see no Hello World is able to see, when open link in browser (http://nodejs-j4nos.rhcloud.com:3000) why?
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
To ssh://5556b4c4fcf9336abf0000de#nodejs-j4nos.rhcloud.com/~/git/nodejs.git/
and here is the tree structure, express is listed
Based on this SO answer I tried to modify script, but does not helped:
var express = require('express');
var app = express();
app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080);
app.set('ip', process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1');
http.createServer(app).listen(app.get('port'), app.get('ip'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
app.get('/', function (req, res) {
res.send('Hello World!');
});
Link is working now: http://nodejs-j4nos.rhcloud.com The right script to show "Hello world!" is
var http = require('http');
var express = require('express');
var app = express();
app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080);
app.set('ip', process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1');
http.createServer(app).listen(app.get('port'), app.get('ip'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
app.get('/', function (req, res) {
res.send('Hello World!');
});
And here is the proof:
Thanks for this: Deployed Node app to OpenShift successfully, OpenShift still shows default page
and this question: Node.js Deployment in openshift
And you should now that you can write in /app-root/repo the $ node server.js command, and if something wrong with script, it will indicate right there
I´ve readed this, maybe you must use a port over 15000:
https://help.openshift.com/hc/en-us/articles/202185874-I-can-t-bind-to-a-port
Found my notes on using OpenShift with Node:
The openshift system has some integrated control tools to support its ‘gear’ system, useful to control the openshift
application and environment.
gear control your application (start, stop, restart, etc)
or deps with --cart (gear start --cart mysql-5.1)
tail_all tail all log files. This command displays the last entries
in your log files as they are written. You can hit
<ctrl>-c to exit this command.
export list available environment variables
rm remove files / directories
ls list files / directories
ps list running applications
kill kill running applications
mysql interactive MySQL shell
mongo interactive MongoDB shell
psql interactive PostgreSQL shell
quota list disk usage
The gear system has additional commands. OpenShift Gear Control, An assortment of gear utilities:
COMMANDS:
build Run the build steps
deploy Run the deploy steps
help Display global or [command] help documentation.
postreceive Run the git postreceive steps
prereceive Run the git prereceive steps
reload Reload a cart
remotedeploy Run the remotedeploy steps
restart Restart a cart
restore Restore an application
snapshot Snapshot an application
start Start the gear/cart
status Get the status for a cart
stop Stop the gear/cart
Will any of this stuff help you stop and restart the gear? I'd start with the simple 'gear' command. I don't remember, is Express loaded up via NPM or now native with node? At one time it was a NPM install. Those don't get pushed to Openshift.
What is the directory tree structure on the openshift nodejs server?
root
\ app-root
\ data
\ repo <- - the working files for web content end up here.
\ runtime
\ git
\ nodejs
In openshift dependencies don't get pushed. For that you can login thru ssh and go to:
cd app-root/repo or cd $OPENSHIFT_REPO_DIR and then npm install tool_of_choice

NodeJS Deployment confusion between localhost and other domain?

I have a simple program which executes fine in localhost.
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
var port = process.env.PORT || 8080;
var host = "127.0.0.1";
var server = app.listen(port, host, function(){
console.log("Server running in : ",host ," with port no : ",port);
});
Trying to deploy the same to heroku using codeship. Everything is building perfect except the last line of deployment test command i.e node index.js which in turn is referring to 127.0.0.1 and stops deploying. May i know do i need to change something here for the host and port address
Just don't provide a host:
var server = app.listen(port, function() {
console.log('Server listening on', port);
});
(This implies, "accept connections on any host, on this port", vs what you're trying which implies, "accept connections on 127.0.0.1 on this port")
Try to run your app on localhost with the help of foreman that is a part of the Heroku Toolbelt. For instance:
foreman start web
You should see your app running on http://localhost:5000 or the port you have specified in your package.json file.
Suggest this link for further queries:
prerequisites to deploy a node app on Heroku?
I was able to host it successfully following through this steps
As suggested by #hunterloftis, i removed hostname.
More importantly, Procfile was missing,so added it and deployed successfully

nodejs app can not run on port 80 using express

I am running the below code taken from express 3.0.3 node_modules/express/test.js:
/**
* Module dependencies.
*/
var express = require('./')
, app = express()
console.log(express.json());
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.cookieParser('foobar'));
app.use(express.session());
app.get('/', function(req, res){
res.send('hello');
});
app.listen(80);
console.log('listening on 80');
Now if I start the node app with "sudo node test.js", the app starts fine and I am able to see the 80 port being listened on using netstat, however when I use browser on port 80, then I do not get any response. But I use any port other than 80, it works.
Can you please let me know what I am missing here?
Why I can not run node app on 80 using express?
With regards,
-M-

Resources