# reflectjs-core

> The simplest reactive web framework, built for Node.js and the browser.

Latest version **0.2.9** (published 2023-09-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install reflectjs-core
pnpm add reflectjs-core
yarn add reflectjs-core
bun add reflectjs-core
```

Provides the command `reflectjs`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.9 |
| Published | 2023-09-10 |
| First published | 2023-04-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16.0.0 |
| Dependencies | 11 |
| Unpacked size | 217.4 KB |
| Known vulnerabilities | 0 (+6 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Fabrizio Capolini |
| Maintainers | reflectjs.org |
| Keywords | reactive, web, framework, server, browser, runtime, HTML |

## Links

- npm: https://www.npmjs.com/package/reflectjs-core
- Repository: https://github.com/reflectjs/reflectjs-core
- Homepage: https://github.com/reflectjs/reflectjs-core#readme
- Issues: https://github.com/reflectjs/reflectjs-core/issues
- npm.io page: https://npm.io/package/reflectjs-core

## Dependencies (11)

- [esprima](https://npm.io/package/esprima.md) ^4.0.1
- [express](https://npm.io/package/express.md) ^4.18.2
- [piscina](https://npm.io/package/piscina.md) ^3.2.0
- [escodegen](https://npm.io/package/escodegen.md) ^2.0.0
- [happy-dom](https://npm.io/package/happy-dom.md) ^8.4.4
- [estraverse](https://npm.io/package/estraverse.md) ^5.3.0
- [markdown-it](https://npm.io/package/markdown-it.md) ^13.0.1
- [markdown-it-attrs](https://npm.io/package/markdown-it-attrs.md) ^4.1.6
- [express-rate-limit](https://npm.io/package/express-rate-limit.md) ^6.7.0
- [markdown-it-anchor](https://npm.io/package/markdown-it-anchor.md) ^8.6.7
- [markdown-it-highlightjs](https://npm.io/package/markdown-it-highlightjs.md) ^4.0.1

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.2.9 (latest) — 2023-09-10
- 0.2.8 — 2023-05-15
- 0.2.7 — 2023-05-11
- 0.2.5 — 2023-05-09
- 0.2.4 — 2023-05-08
- 0.2.2 — 2023-04-13
- 0.2.1 — 2023-04-05
- 0.2.0 — 2023-04-02
- 0.1.0 — 2023-04-02

## README

# Reflect.js

[![CodeQL](https://github.com/reflectjs/reflectjs-core/actions/workflows/codeql.yml/badge.svg)](https://github.com/reflectjs/reflectjs-core/actions/workflows/codeql.yml)
[![Node.js CI](https://github.com/reflectjs/reflectjs-core/actions/workflows/node.js.yml/badge.svg)](https://github.com/reflectjs/reflectjs-core/actions/workflows/node.js.yml)
![Coverage](https://github.com/reflectjs/reflectjs-core/raw/main/res/coverage-badge-230423.svg)

**The HTML-oriented reactive framework**

---

Using a reactive framework in modern web development can be pretty involved &mdash;&nbsp;but&nbsp;it&nbsp;doesn't&nbsp;have&nbsp;to&nbsp;be.

Reflect.js is a groundbreaking alternative which strives for simplicity:

1. it turns HTML itself into a [reactive language](https://reflectjs.org/docs/introduction#reactivity)
2. it generates fully [indexable pages](https://reflectjs.org/docs/introduction#indexability) out of the box
3. it makes it easy to create your own [reusable components](https://reflectjs.org/docs/introduction#reusability).

It's implemented as a customizable [Express](https://expressjs.com/) server for [Node.js](https://nodejs.org/). It augments HTML with `:`-prefixed [attributes](https://reflectjs.org/docs/reference/language#values), `[[...]]` [expressions](https://reflectjs.org/docs/reference/language#expressions), and `<:...>` [directives](https://reflectjs.org/docs/reference/language#directives), and it's easy to pick up.

Page-specific JavaScript code for both the client and the server is  compiled on the fly as needed &mdash; you only have to focus on page logic and the server takes care of the rest.

Reflect.js removes all the boilerplate code associated with JS-oriented reactive web frameworks like [React](https://react.dev/) and [Vue.js](https://vuejs.org/), while still encouraging good practices and code reuse &mdash; you'll be surprised at how effective it can be.

> Reflect.js is still under development. We plan to reach v.1.0 later in 2023.

## Hello World

1. create a dir and install the package:

```sh
mkdir myapp && cd myapp
npm install reflectjs-core
npx reflectjs
# ... START http://localhost:3001
```

2. add `index.html`

```html
<html>
  <body :count="[[0]]"
        :did-init="[[
          setInterval(() => count++, 1000);
        ]]">
    Seconds: [[count]]
  </body>
</html>
```

3. navigate to http://localhost:3001 to see the seconds counter live.

> If you install globally with `npm install -g reflectjs-core` you can just launch the server from any directory with the `reflectjs` command.

## Use in a project

1. create the project

```sh
mkdir myproject cd myproject
npm init -y
npm install reflectjs-core
mkdir docroot
```

2. add an entry point

```js
// index.js
const reflectjs = require('reflectjs-core');
const path = require('path');

new reflectjs.Server({
  port: 3002,
  rootPath: path.join(__dirname, 'docroot'),
});
```

in TypeScript we can use imports instead

```ts
// index.ts
import { Server } from 'reflectjs-core';
import path from 'path';

new Server({
  port: 3002,
  rootPath: path.join(__dirname, 'docroot'),
});
```

3. add `docroot/index.html`

```html
<html>
  <body :count="[[0]]"
        :did-init="[[
          setInterval(() => count++, 1000);
        ]]">
    Seconds: [[count]]
  </body>
</html>
```

4. run the project:

```sh
node index.js
# ... START http://localhost:3002
```

5. navigate to http://localhost:3002 to see the seconds counter live.

> When using Reflect.js in a project you can configure it and add your own services and middleware. All options are documented in the [Server Reference](https://reflectjs.org/docs/reference/server).

## Next steps

* [Introduction](https://reflectjs.org/docs/introduction) &mdash; get the gist of Reflect.js
* [Tutorial](https://reflectjs.org/docs/tutorial) &mdash; get a taste of Reflect.js development
* [Reference](https://reflectjs.org/docs/reference/language#values) &mdash; find all the details

---
_Source: https://npm.io/package/reflectjs-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
