What is this?
Running the server
npx jhp-serve ./my-proj # Assumes you have Node/npm installed
my-proj/ index.html.js about.html.js contact.html.js
// index.html.jsmodule`<h1>Hello!</h1><p>Thanks for visiting the page at</p>`
A jhp project is just a directory containing
.html.js files and/or static
.html.js files are analogous to
.php files, in that each handles one
route and (usually) renders one page. For both kinds of files, the route is the
same as the subdirectory relative to the project root. You do not need to
restart the server to test changes made to your
.html.js file exports a single function which returns either an HTML
string, or a Promise of an HTML string. The latter is useful if, for example,
you need to query a database before rendering the HTML.
Render functions are passed two optional arguments,
res, which are
the ExpressJS Request and
Response objects. The response's
content type has already been set to HTML, so that the common case of returning
an HTML string doesn't have to mess with it. The request body is parsed as being
"form-encoded", meaning it will work as expected for native HTML forms.
libraries or do whatever additional logic you may want to do in them.
A full example site can be found here: https://github.com/brundonsmith/jhp-example-site
When it comes to syntax highlighting of the HTML itself, your mileage may vary depending on your editor. From a quick search it appears that Atom may have this built-in. VSCode at least has some great extensions that give the template strings first-class status as HTML code including syntax highlighting, formatting, autocomplete, etc. Here are a couple of them:
If you plan on having additional server code, I recommend making your JHP site a subdirectory of your overall project, so that your server code and config files aren't served publicly on the web.