@xtaskjs/express-http
v1.0.19
Published
Express HTTP adapter for xtaskjs.
Readme
@xtaskjs/express-http
Express adapter package for xtaskjs HTTP applications.
This package is part of the xtaskjs project, hosted at xtaskjs.io.
Installation
npm install @xtaskjs/express-httpUsage
import express from "express";
import { ExpressAdapter } from "@xtaskjs/express-http";
import { CreateApplication, view } from "@xtaskjs/core";
const expressApp = express();
const application = await CreateApplication({
adapter: new ExpressAdapter(expressApp),
});
await application.listen({ port: 3000 });
// In a controller:
return view("home", { title: "Hello" });By default, ExpressAdapter uses:
views/as templates directorypublic/as static assets directory (/app.css,/images/logo.png, etc.).htmlas the template extension for filesystem templates
Custom Views/Public Paths
import path from "path";
const adapter = new ExpressAdapter(expressApp, {
templateEngine: {
viewsPath: path.join(process.cwd(), "resources/views"),
fileExtension: ".html",
},
staticFiles: {
publicPath: path.join(process.cwd(), "resources/public"),
urlPrefix: "/",
},
});Native Express Engines (pug, hbs, ejs)
import path from "path";
import { engine as hbsEngine } from "express-handlebars";
const adapter = new ExpressAdapter(expressApp, {
templateEngine: {
viewsPath: path.join(process.cwd(), "views"),
extension: "hbs",
engine: hbsEngine(),
viewEngine: "hbs",
},
});You can also use the adapter shortcut in @xtaskjs/core:
await CreateApplication({
adapter: "express",
adapterInstance: expressApp,
});Resources
- Project site and documentation: xtaskjs.io
- npm package: @xtaskjs/express-http
- Source repository: xtaskjs/xtaskjs
