APIs & Integrations

boartsy
Member

Building Your First Web App

Hi, what's wrong with my code :

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

app.set('port', (process.env.PORT || 5000));

app.use(express.static(__dirname));

// views is directory for all template files
app.set('views', __dirname + '/html');
app.set('view engine', 'ejs');

app.get('/', function(request, response) {
response.render('pages/index');
});

app.get('/about', function(request, response) {
response.render('pages/about');
});

app.get('/projects', function(request, response) {
response.render('pages/projects');
});

app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});


// This file is what handles incoming requests and
// serves files to the browser, or executes server-side code
 
Thanks, 
Bo
0 Upvotes
1 Reply 1
RMones
Contributor | Platinum Partner
Contributor | Platinum Partner

Building Your First Web App

Hi @boartsy ,

 

There is nothing wrong with you code.
You are serving a webserver with express on port 5000.

I copied your code, did npm install ejs and created a index.ejs file in html/pages/ and started the webserver.

After that my index.ejs was served on localhost:5000.

 

Regards Ronald