Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot find view in node/express
    primarykey
    data
    text
    <p>As my username implies, I'm new to node.js. I'm trying to learn it. As part of this process, I'm working to setup a basic web site. This web site will show a couple of basic web pages and expose a single REST endpoint. The structure of my project is:</p> <pre><code>config.js home.html start.js routes.js server.js resources css style.css images up.png down.png javascript home.html.js </code></pre> <p>start.js has my main server code. That file gets executed via command line using 'node start.js'. Once started, my server begins listening on port 3000. The code in start.js looks like this:</p> <pre><code>var express = require('express'); var app = express(); var UserProfileHandler = require('./app/handlers/UserProfileHandler'); app.configure(function () { app.engine('html', require('ejs').renderFile); app.set('views', __dirname + '/'); app.use(express.logger({ stream: expressLogFile })); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(__dirname + '/public')); }); var routes = { userProfiles: new UserProfileHandler() }; function start() { routeConfig.setup(app, routes); var port = process.env.PORT || 3000; app.listen(port); console.log("SUCCESS: Server listening on port %d in %s mode", port, app.settings.env); } exports.start = start; exports.app = app; </code></pre> <p>My routes.js file has the following:</p> <pre><code>function setup(app, routes) { viewSetup(app); apiSetup(app, routes); } function viewSetup(app) { app.get('/', function (req, res) { res.render("/home.html"); }); app.get('/home.html', function (req, res) { res.render("/home.html"); }); } function apiSetup(app, routes) { app.get('/api/userProfiles/:username', routes.userProfiles.getUserProfiles); } </code></pre> <p>I am trying to load home.html in a browser window. I attempt this by visiting <code>http://localhost:3000</code> and <code>http://localhost:3000/</code> and <code>http://localhost:3000/home.html</code>. Unfortunately, none of these work. In fact, I receive an error that says:</p> <p>Express 500 Error: Failed to lookup view "/home.html"</p> <p>I know that I'm close. If I visit <code>http://localhost:3000/api/userProfiles/me</code> I receive a JSON response back like I'm expecting. For some reason, i can't seem to return HTML though. My home.html file looks like the following.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type='text/javascript' src='/resources/javascript/home.html.js'&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; We're up and running! &lt;img src='/resources/images/up.png' /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Its a pretty basic HTML file. Even if the HTML comes back though, I'm concerned the JavaScript file and Image it references won't be accessible. I'm concerned of this because I'm not really sure how paths and such work in Node.</p> <p>How do I get home.html to work in my Node setup?</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload