Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What I think you are trying to say is: How can I serve static html files, right?</p> <p>Let's get down to it.</p> <p>First, some code from my own project:</p> <pre><code>app.configure(function() { app.use(express.static(__dirname + '/public')); }); </code></pre> <p>What this means that there is a folder named public inside my app folder. All my static content such as css, js and even html pages lie here.</p> <p>To actually send static html pages, just add this in your app file</p> <pre><code>app.get('/', function(req, res) { res.sendFile(__dirname + '/public/layout.html'); }); </code></pre> <p>So if you have a domain called xyz.com; whenever someone goes there, they will be served layout.html in their browsers.</p> <p><strong>Edit</strong></p> <p>If you are using express 4, things are a bit different. The routes and middleware are executed exactly in the same order they are placed.</p> <p>One good technique is the place the static file serving code right after all the standard routes. Like this :</p> <pre><code>// All standard routes are above here app.post('/posts', handler.POST.getPosts); // Serve static files app.use(express.static('./public')); </code></pre> <p>This is very important as it potentially removes a bottleneck in your code. Take a look at this <a href="https://stackoverflow.com/questions/12695591/node-js-express-js-how-does-app-router-work">stackoverflow answer</a>(the first one where he talks about optimization)</p> <p>The other major change for express 4.0 is that you don't need to use app.configure()</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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