Node Website(App), I cannot make multiple pages


#1

I’m making a site with express using the node app template. I am not able to make multiple pages like www.site.glitch.me/home or www.site.glitch.me/about. I’ve tried and it won’t work.


#2

Bump((fillercontenthere))


#3

There’s a page on using routing in Express here: https://expressjs.com/en/guide/routing.html

But using the node-app template you could add routes for your home and about pages like so:

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

// we've started you off with Express, 
// but feel free to use whatever libs or frameworks you'd like through `package.json`.

// http://expressjs.com/en/starter/static-files.html
app.use(express.static('public'));

// http://expressjs.com/en/starter/basic-routing.html
app.get('/', function(request, response) {
  response.sendFile(__dirname + '/views/index.html');
});

// http://expressjs.com/en/starter/basic-routing.html
app.get('/home', function(request, response) {
  response.sendFile(__dirname + '/views/home.html');
});

// http://expressjs.com/en/starter/basic-routing.html
app.get('/about', function(request, response) {
  response.sendFile(__dirname + '/views/about.html');
});

// listen for requests :)
var listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});

You would need to create the home.html and about.html files in the views directory.

Note that the site would be accessible at site.glitch.me and not www.site.glitch.me as we don’t make the www sub-sub-domain available to sub-domains.


#4

Looks like www.site.glitch.me redirects to site.glitch.me