Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs express apps in small orange

I am new to "A Small Orange" and I am trying to run an express app in small orange following this link

I first created the following directory structure

/home/user/servercode/myapp with tmp directory and app.js file /home/user/public_html/clientCode/myapp with .htaccess

/home/user/servercode/myapp/tmp contains an empty restart.txt file In /home/user/servercode/myapp, I ran

npm init 
npm install express --save

This is my app.js. Pretty much same as the one in the link mentioned in the post

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

app.get('/', function (req, res) {
  res.send('Hello World Express App');
});

if (typeof(PhusionPassenger) != 'undefined') {
    console.log( 'Example app listening with passenger' );
app.listen('passenger');
} else {
    console.log( 'Example app listening with 3000' );
    app.listen(3000);
}

.htaccess has 644 permission level and contains this

PassengerEnabled on
PassengerAppRoot /home/user/serverCode/myapp
SetEnv NODE_ENV production
SetEnv NODE_PATH /usr/lib/node_modules

When I try to access myapp, I get this error Cannot GET /myapp/ and 404 in browser console

I could get a normal nodejs application running without express with the below content in app.js

var http = require('http');
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});
server.listen(8000);
console.log("Server running at http://127.0.0.1:8000/");

But not able to get express app running

like image 627
Preethy Srikanthan Avatar asked Jul 11 '26 03:07

Preethy Srikanthan


1 Answers

You need to add route in you application as :

app.get('/myapp', function(req, res){...});
like image 68
Aman Gupta Avatar answered Jul 13 '26 17:07

Aman Gupta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!