
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
nest-jsx-template-engine
Advanced tools
JSX-based + typescript template engine for NestJS applications
This is a template engine for Nestjs applications that allows you to use JSX-based templates with strongly-typed params for server-side rendered HTML.
You don't need any extra templating engine like nunjucks or handlebars, and you get type-safety out of the box.
There's no additional compiler, since TypeScript compiles JSX natively.
Install the package:
npm install nest-jsx-template-engine
Update your tsconfig.json
file to include jsx
and jsxFactory
options:
{
"compilerOptions": {
"jsx": "react",
"jsxFactory": "h"
}
}
Install the middleware in your Nest app.module
:
// app.module.ts
import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { RenderMiddleware } from 'nest-jsx-template-engine';
import { SomeModule } from './some/some.module';
@Module({
imports: [SomeModule],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(RenderMiddleware)
.forRoutes('*');
}
}
Suggest installing it globally for all routes, but see Nest's documentation for other options on installing the middleware.
// app.controller.ts
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { Render } from 'nest-jsx-template-engine';
import { App } from './app.view';
import { AppViewTransferObject } from './app.vto';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
@Render(App) // pass the App view directly to the Render decorator
getHello(): AppViewTransferObject {
return this.appService.getHello();
}
}
Define your template with JSX:
// app.view.tsx
import { h } from 'nest-jsx-template-engine'
import { AppViewTransferObject } from './app.vto'
export function App(props: AppViewTransferObject): string {
return <html>
<body>
<h1 class="foo">{props.name}</h1>
</body>
</html>
}
You can define a view-transfer interface for the props passed into your template. This way, you can strongly-type the values passed from your controller into your view.
// app.vto.ts
export interface AppViewTransferObject {
name: string
}
See a working demo in the Github repo.
This package does not support React flavored JSX (e.g., className
, htmlFor
, etc). It expects basic HTML properties.
FAQs
JSX-based + typescript template engine for NestJS applications
The npm package nest-jsx-template-engine receives a total of 6 weekly downloads. As such, nest-jsx-template-engine popularity was classified as not popular.
We found that nest-jsx-template-engine demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.