GithubHelp home page GithubHelp logo

lite-jsx / express Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 43 KB

Middleware that uses lite-jsx to render JSX templates in an Express application.

Home Page: https://lite-jsx.github.io/core/#/

License: MIT License

JavaScript 100.00%
express express-middleware html jsx

express's Introduction

Lite JSX - Express Middleware

License Build Actions NPM Version NPM Downloads

Lite JSX is a lightweight JavaScript library that allows you to create and manipulate JSX elements using only vanilla JavaScript.


Installation

You can install Lite JSX via npm:

npm install @lite-jsx/core @lite-jsx/express

Using Lite JSX with Express

To use Lite JSX with Express, you can create a middleware that overrides the default res.render function to add support for JSX templates. Here's an example:

const express = require("express");
const { liteJsx } = require("@lite-jsx/express");
const Home = require("./home");

const app = express();

// Use the middleware to enable Lite JSX rendering in the Express app.
app.use(liteJsx);

// Render the component using Express.
app.get("/", (req, res) => {
  const data = { message: "Hello, world!" };
  // the render method now is override to use jsx components
  res.render(Home, data);
});

app.listen(3000, () => {
  console.log("Server is listening on port 3000!");
});

To enable Lite JSX in our Express app, we're using the liteJsx middleware, which overrides the default res.render function to add support for JSX templates.

This way, we can pass a JSX component to res.render and it will be rendered as HTML.

And that's it! With these few lines of code, you can start using Lite JSX with Express to create powerful, dynamic web applications.


Contributing

If you'd like to contribute to Lite JSX, please feel free to submit a pull request or open an issue on GitHub:

https://github.com/lite-jsx/express

License

Lite JSX is licensed under the MIT License.

express's People

Contributors

danprates avatar github-actions[bot] avatar

Stargazers

Juliet Wang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.