# stream-render

> render your templates asynchronously

Latest version **2.0.0** (published 2016-09-06) · SEE LICENSE IN LICENSE license · 0 weekly downloads

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

## Install

```sh
npm install stream-render
pnpm add stream-render
yarn add stream-render
bun add stream-render
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2016-09-06 |
| First published | 2016-08-17 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.3.1 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | robojones |
| Maintainers | robojones |
| Keywords | render, template, asynchronously, async, stream, templates |

## Links

- npm: https://www.npmjs.com/package/stream-render
- Repository: https://github.com/robojones/stream-render
- Homepage: https://github.com/robojones/stream-render#readme
- Issues: https://github.com/robojones/stream-render/issues
- npm.io page: https://npm.io/package/stream-render

## Dependencies (1)

- [extend](https://npm.io/package/extend.md) ^3.0.0

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2016-09-06
- 1.0.2 — 2016-09-06
- 1.0.1 — 2016-08-17
- 1.0.0 — 2016-08-17

## README

# stream-render - render templates asynchronous
## Introduction
With `stream-render` you can insert information into files before you send them to the user.
The advantage of `stream-render` is that it processes your file line by line so it uses few memory and the processed lines can be send to the user immediately.
## Installation
`npm install stream-render`
## Templates
The easiest way is to create a directory called `views` in your projects folder.
Then you can create Templates in this directory.
There is no special file extension that you have to use. You can use `.html`, `.txt` and others.
## Example - Template
This is a file called `<pathToYourProject>/views/example.txt`
```
@// use ` and ´ to seperate your js code from other contents.
Hello `username´,
Welcome to our site! three times hurray!

@// if you put an @ in the beginning of a line the whole line gets interpreted as js
@ for(let i = 0; i < 3; i++) {
Hurray
@ }

```
Note: You must add an empty line at the end of your file.
## Example - The Result
The file you get from your server after rendering it would look like that:
```
Hello Hans,
Welcomt to our site! three times hurray!

Hurray
Hurray
Hurray

```
## Example - Using stream-render with http-server
```
const http = require('http');
const render = require('stream-render');

const server = http.createServer((req, res) => {
  
  // our template needs some information
  const data = {
    username: 'Hans'
  };
  
  // render our example template
  render(res, 'example.txt', data).then((stream)=>{
    stream.end();
  });
});

server.listen(3000, function () {
  console.log(`Server running on port`, port);
});
```
## Example - Using stream-render with express
```
const app = require('express')();
const render = require('stream-render');

app.get('/example', function (req, res) {
  
  // our template needs some information
  const data = {
    username: 'Hans'
  };
  
  // render our example template
  render(res, 'example.txt', data).then((stream)=>{
    stream.end();
  });
});

app.listen(3000, function () {
  console.log('App listening on port 3000!');
});
```

## Arguments
When you are calling the `render()` method you have to provide the following arguments:

1. A writable stream
2. The filename of the template
3. The data to render into the template

## Returns
The `.render` method returns a promise that will be resolved when the rendering has been completed.

Note: The promise will never be rejected.

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