JavaScript Error when rendering HTML in express error when rendering 'memory.total physical',error when

I'm trying out a simple one page render and I'm obviously doing it wrong:

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

app.get('/', function(req, res){
   res.render('home.html');
});

app.listen(3000);
console.log('Listening on port 3000');

Error:

Error: Cannot find module 'html'

I want to load a page with CSS/images and wanted to know where to store the CSS/images/scripts/HTML and how to load it. I have yet to find many example express apps.

Answer:1

When using res.render, you are rendering a defined view. The documentation state:

Render a view with a callback responding with the rendered string. When an error occurs next(err) is invoked internally.

For specific HTML, you either have to load the file with fs.readFile, or have Express use a rendering engine, such as Jade or EJS. For example, this code sample would apply the EJS render engine to all files with the extension .html.

app.engine('html', require('ejs').renderFile);

Then you can render a file like this. This is an example of passing variables to the HTML file, because that's what embedded JavaScript is used for.

app.get('/', function (req, res) {
  res.render('/file', {
    pass: 'arguments',
    to: 'the file here'
  });
});

That is more convenient than having to read the file on each load like so:

app.get('/', function (req, res) {
  fs.readFile('/index.html', 'utf8', function (err, data) {
    res.send(data);
  });
});

Although this is aside from your question, this is how passing variables to EJS works. It even works with if statements and loops, since it accepts all JavaScript. Putting console.log in the file would log each time the file was rendered.

<span><%= pass %></span>
<!-- after rendering -->
<span>arguments</span>

If you need to serve other resources, such as CSS, JavaScript, or other html files, you could use Express' directory function.

app.use(express.static('/'));

Then you wouldn't need to render your HTML at all. It would be statically served.

Answer:2

I want to load a html with css/images and wanted to know what is the layout of where to store the css/img/js and the html and load it? I am yet to find many example express js apps.

Assuming that you have installed express, within your express project you will find public folder. within public folder you will find three folder - images, javascripts, and stylesheets . As the names suggest place your css/img/js in their respective folders.

Answer:3

Is there a way to order an array by the output of another filter? I have an expression like this: <li ng-repeat="sub in subscriptions"> {{sub | subscriptionOutput}} </li> Here ...

Is there a way to order an array by the output of another filter? I have an expression like this: <li ng-repeat="sub in subscriptions"> {{sub | subscriptionOutput}} </li> Here ...

  1. combining like terms
  2. combining like terms worksheet
  3. combining pdf files
  4. combining form
  5. combining sentences
  6. combining cells in excel
  7. combining pdfs
  8. combining synonym
  9. combining like terms worksheet pdf
  10. combining vowel
  11. combining functions
  12. combining names
  13. combining sentences worksheet
  14. combining like terms activity
  15. combining like terms and distributive property worksheet
  16. combining word documents
  17. combining like terms puzzle
  18. combining like terms with negative coefficients
  19. combining exponents
  20. combining like terms video

This is quite an in depth question so I will try my best to explain in as much detail as possible. I am creating a Wordpress game information website, there are rows of gamelistings which when ...

This is quite an in depth question so I will try my best to explain in as much detail as possible. I am creating a Wordpress game information website, there are rows of gamelistings which when ...

I have a little question. I try to build this simple quiz. Right now it looks like this: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"...

I have a little question. I try to build this simple quiz. Right now it looks like this: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"...

  1. jquery each element with class
  2. jquery each element with data attribute
  3. jquery each element in array
  4. jquery each element in div
  5. jquery each element loop
  6. jquery each element with id
  7. jquery each element index
  8. jquery each element find
  9. jquery each element value
  10. jquery each element click
  11. jquery each element with class name
  12. jquery each element with name
  13. jquery each element remove class
  14. jquery each element in form
  15. jquery each element starting with
  16. jquery each element attribute

Does anyone know if there's a way to add text into the tumblr ask box when the page is first loaded? I'm running a blog where people can ask for advice from either a girl or a guy. I want them to ...

Does anyone know if there's a way to add text into the tumblr ask box when the page is first loaded? I'm running a blog where people can ask for advice from either a girl or a guy. I want them to ...

  1. insert text into pdf
  2. insert text into excel
  3. insert text into picture
  4. insert text into imovie
  5. insert text into excel formula
  6. insert text into photo
  7. insert text into cell vba
  8. insert text into photoshop
  9. insert text into excel cell
  10. insert text into a shape in word
  11. insert text into string python
  12. insert text into word document
  13. insert text into picture in word
  14. insert text into equation latex
  15. insert text into video
  16. insert text into premiere
  17. insert text into image
  18. insert text into file linux
  19. insert text into pdf free
  20. insert text into html