0

Ok I am making website and want to use mongo, express, etc. I setup a server using fedora server ISO. The problem is getting node working. I have followed several tutorials, and its all the same. Nothing works. So I have to be doing something wrong. Trying to get the simplest thing to display on screen.

I think the server is running httpd server, whatever fedora has built in. I get the default fedora server page when going to the url. So the server is running and working, just hasn't been configured. When running node on the server do I have to use httpd-node? Or can it be http, etc.

Here is my app.js

const express = require('express')
const app = express()

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

app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
})

And then I have a basic index.html that should be rendered just saying test.

I ssh into the server and run node start, it runs and the console logs the message like it should. But if I go to the address 192.168.1.5, or the domain that points to the server, I get nothing, just a blank page.

If someone can help me get this working, I can actually get to work coding out the application. Any help would be appreciated.

Seva
  • 15
  • 6
  • You do not run _node on the server_, node **is** the server. – TGrif Aug 11 '17 at 09:05
  • wait.. so to host a website with node... you don't use a server? I thought node was the "App sever" that runs on the "server" – Seva Aug 12 '17 at 01:44

2 Answers2

0

res.send('Hello World!') - this is your problem! Why?

How you receive this answer on client side?

Solution: use res.render(..) - for rendering from server or use AJAX on client side for receive this text!

P.S: render page and you don't see blank page anymore! Or use client-server conversation logic with your server through AJAX.

Try 192.168.1.5:3000

If I wrong: show your full project setup... Test your app with curl (https://curl.haxx.se)! Check connection establishment, and show results here!

Liam
  • 27,717
  • 28
  • 128
  • 190
0

I think you make a confusion. When you build an Express application, you do not need another server at all.

When you start your app with:

app.listen(3000, function () {})

Express returns an http.Server object listening to port 3000.
When you navigate to your local adress on port 3000, you will see your "hello world" message.

It is possible that httpd service is already running in your Fedora environnement on default port 80 (the default port for http, the one your reach when you go to your local adress) but this is an Apache server and you do not need it to run your Nodejs app.

To build a Nodejs server, you can also use httpd-node package, but this is redundant as you're using Express framework.

If you need to serve a simple html file, a method I like for its simplicity is to use ejs template engine, something like this.

TGrif
  • 5,725
  • 9
  • 31
  • 52