How to use Poet with Node, Express and EJS template engine - node.js

I discovered the Poet blog engine and I would like to know how to use it with the EJS template engine.
Also, even with the documentation, I don't understand how to create new post, in which format, and how it's rendered in the webpage.

There's an old PR for examples using EJS instead of Jade. It's pretty much just like the examples in the examples/ dir, except just change express' view engine to ejs and use ejs templates instead.

Related

How do I use ReactJs with an existing project that uses EJS Express Mongodb as stack?

The file structure is based on sailsjs structure, we don't use sailsjs though, this is how it looks like:
Stack used is : EJS Express/Node MongoDb.
I want to move a certain page from ejs to ReactJS and also implement Webpack with it.
Is there a way I can convert this into a react app, or simply use react with ejs ?
You can use try react cdn links as script tags.
https://reactjs.org/docs/cdn-links.html

How Does Node.js + Express Find Pre-Rendered Views?

I would like to pre-render my Jade files with a Gulp task, so that my views are not rendered on-the-fly. From my understanding, if one is using the Jade view engine with Express 4, this is how the Jade templates become their HTML equivalents (please correct me if I am wrong).
I realize that the views directory is typically pointed to using the statement app.set('views', __dirname + '/views/directory');, where app is an Express app. However, I am not sure how to force Express to serve the pre-rendered HTML files instead.
Any suggestions are appreciated.

Express - Create a new view engine

I know that expressjs supports many view engines, like: ejs, jade, etc. I saw a list here: http://expressjs-book.com/forums/topic/how-to-use-alternative-non-jade-template-engines-with-express/.
My question is how can I create my own view engine. I've looked in ejs and in other engines' source-code but I didn't really find an expressjs documentation on how to create a new engine, what are the requirements, or a tutorial about it.
Is it possible to create a new custom view engine? Thanks.
Yes, of course. Take a look at this list for templating engines.
Regarding express itself, what you need to do is create a plugin, or even a middleware function - that will attach your render, renderFile and similar methods to the response object.
If you don't use an express engine and try to, say, response.render('index.ejs');, you'll get an error. But if that response object has a render method, you're fine. So it boils down to extending expresses' response object with what you need.

Is it possible to use nodejs express with any jquery library like datatables?

I want to be able to use nodejs with jquery without having to execute an npm install as I want to use jquery strictly on the client side. I know this is not possible with the Jade templating engine as its syntax is completely different, but is it possible with some other templating engine? I would prefer not to have a bunch of HTML to haml just to make nodejs happy.
It is certainly possible to use jQuery or any other JavaScript client-side library with Jade. You'll need to figure out the syntax to include a JavaScript file and JavaScript code with whatever engine you use. With Jade you can use script() to include an external file (like the jQuery library) and then script to code your specific calls. Take a look at the Jade documentation here: https://github.com/visionmedia/jade#readme
Below is an example of a Jade file that (1) includes jQuery and then (2) updates an HTML element ("message") through jQuery:
doctype 5
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
script(src='http://code.jquery.com/jquery-1.8.1.js')
body
h1= title
p#container Welcome to #{title}
p#message (to be filled in)
script
alert('hello world');
$("#message").html("message set through jquery")
Don't think of Jade as a different language or something that is in any way incompatible with your existing HTML/JS stack - it's just a shorthand way to write HTML which allows you to inject server-side data as a byproduct.
For my personal stack I use express + jade on the server side and then angularjs, jquery and twitter bootstrap on the client side. I use require.js to manage all of my imports, and in my jade template I just have a single script() reference that points to the main.js file that has all of my require.js logic in it.
But, as far as express/jade go - the key is to make sure that you understand that it's not there to complicate your life, it's there to make your life easier. If you feel like it's confusing, switch to a different templating engine or simply have express serve up static html pages with nothing injected and set up AJAX services to get the server-side data you need.

node.js - what are the advantages of using jade

I learnt that JADE is a template language and it is preferred engine for express.
What are the advantages of using JADE instead of html ? Is it possible to use html directly instead of using jade ?
Jade has a cleaner, more readable syntax and comes with filters and helpers: https://github.com/visionmedia/jade#a7
If you're going to migrate HTML files to jade, this converter might come handy:
http://html2jade.aaron-powell.com/
...but you can also use HTML.
app.set('view engine', 'html');
http://expressjs.com/guide.html#view-rendering
I'm using EJS ( http://code.google.com/p/embeddedjavascript/) as the rendering engine in my express app, but keep a .html suffix on the template files like this:
app.set('view engine', 'html');
app.register('.html', require('ejs'));
(requires ejs be installed, which you can easily do via npm install ejs)
As a templating engine, it's all about syntax.
You type faster and it improves readability, which means maintainability and productivity. Some of them have better features than others, but in the end it's often a matter of taste.
Express support a lot of templating engines available with nodejs :
http://expressjs.com/guide/using-template-engines.html
Which template engines does Express support?
Anything that can conform with the (path, locals, callback) signature. To normalize template engine interfaces and caching it's recommended to check the consolidate.js project for support. Unlisted template engines may still support the Express signature.
You should check the consolidate.js project, there is some integration examples with Express and gives a good overview of all the templating engines available for node.
The choice is up to you, regarding your needs.

Resources