Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5942001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:11:24+00:00 2026-05-22T16:11:24+00:00

All pages on my 5 page site should be output using a Node.js server.

  • 0

All pages on my 5 page site should be output using a Node.js server.

Most of the page content is static. At the bottom of each page, there is a bit of dynamic content.

My node.js code currently looks like:

var http = require('http'); 

http.createServer(function (request, response) {

    console.log('request starting...');

    response.writeHead(200, { 'Content-Type': 'text/html' });

    var html = '<!DOCTYPE html><html><head><title>My Title</title></head><body>';
    html += 'Some more static content';
    html += 'Some more static content';
    html += 'Some more static content';
    html += 'Some dynamic content';
    html += '</body></html>';

    response.end(html, 'utf-8');

}).listen(38316);

I’m sure there are numerous things wrong about this example. Please enlighten me!
For example:

  • How can I add static content to the
    page without storing it in a string as a variable value with += numerous times?
  • What is the best practices way to build a small site in Node.js where all pages are a mix between static and dynamic content?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:11:25+00:00Added an answer on May 22, 2026 at 4:11 pm

    Personally, I’d use a server that has higher level constructs. For instance, take a look at the expressjs framework – http://expressjs.com/

    The constructs you’ll be interested in from this package are:

    • Truly static files (assets etc): app.use(express.static(__dirname + ‘/public’));
    • A templating language such as jade, mustache, etc:
      • http://expressjs.com/en/guide/using-template-engines.html
      • https://github.com/visionmedia/jade/
      • You’ll want to look up ‘locals’ and ‘partials’ for embedding small bits of dynamic content in mostly static content

    For example in jade:

    !!! 5
    html(lang="en")
      head
        title= pageTitle
        script(type='text/javascript')
          if (foo) {
             bar()
          }
      body
        h1 Jade - node template engine
        #container
          - if (youAreUsingJade)
            p You are amazing
          - else
            p Get on it!
    

    Becomes:

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <title>Jade</title>
        <script type="text/javascript">
          if (foo) {
            bar()
          }
        </script>
      </head>
      <body>
        <h1>Jade - node template engine</h1>
        <div id="container">
          <p>You are amazing</p>
        </div>
      </body>
    </html>
    

    If you prefer something a little less drastic I would say look at mustache or one of the other engines that looks a bit more like regular-sauce html.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what I have: a google search form (displayed on all pages) a wordpress page
I have one master page which applies to all pages in this website. On
Hi i'm wondering how to redirect a http://mysite.com/pdf/blah.pdf to http://mysite.com/pages/page.aspx for all pdf file
I have an intermediary class extending System.Web.UI.Page for all of my pages that require
My wordpress is not setting the front page correctly, I have several pages, all
I have an existing site build in c# 3.5 using asp.net mvc 1. There
I want to make a multi-language site, such that all or almost all pages
I am using a mod_rewrite to force two pages to use HTTPS, while all
I have a private site that requires login for all pages. When a user
I need to redirect all page requests (php, if that matters) on a specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.