
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
nestjs-tsx-views
Advanced tools
Controller:
import { Controller, Get, Render } from "@nestjs/common";
import { MyViewProps } from "./views/my-view";
@Controller()
export class AppController {
@Get()
@Render("my-view")
index(): MyViewProps {
return { name: "world" };
}
}
views/my-view.tsx:
import React, { ReactElement } from "react";
import { MainLayout } from "./layouts/main";
export interface MyViewProps {
name: string;
title: string;
}
const MyView = ({ name, ...props }: MyViewProps): ReactElement => (
<div>Hello {name}</div>
);
export default MyView;
.js / node) and uncompiled files (.tsx / ts-node, ts-jest, ...)$ npm install --save nestjs-tsx-views
Import the module with TsxViewsModule.register(...) or TsxViewsModule.registerAsync(...).
Use TsxViewsModule.register(). Available options are described in the TsxViewsModuleOptions interface.
@Module({
imports: [
TsxViewsModule.register({
viewsDirectory: resolve(__dirname, "./views"),
prettify: true,
forRoutes: [AppController],
}),
],
})
export class MyModule {}
If you want to use retrieve you TSX views options dynamically, use TsxViewsModule.registerAsync(). Use useFactory and inject to import your dependencies. Example using the ConfigService:
@Module({
imports: [
TsxViewsModule.registerAsync({
useFactory: (config: ConfigService) => ({
viewsDirectory: resolve(__dirname, './views'),
prettify: config.get('PRETTIFY_HTML'
)
forRoutes: [AppController],
}),
inject: [ConfigService],
}),
],
})
export class MyModule {}
import { createContext } from 'react'
export interface MyContextProps {
name: string
}
export const MyContext = createContext<MyContextProps | undefined>
@Controller()
export class AppController {
constructor(private readonly ssr: TsxViewsService) {}
@Get()
@Render("my-view")
index() {
this.#ssr.addContext(MyContext, { name: "My context data" });
return {};
}
}
import { useContext } from "react";
import { MyContext } from "./my-context";
export function MyComponent() {
const { name } = useContext(MyContext);
return <span>Hallo, {name}!</span>;
}
This module supports the execution of GraphQL queries from the TSX template. For this purpose graphql, @apollo/client and cross-fetch have to be installed separately:
$ npm install --save @apollo/client cross-fetch graphql
See example/graphql/app.module.ts for a working example of how to configure the NestJS module. View example:
// example/graphql/views/my-view.tsx
export interface Film {
id: string;
title: string;
releaseDate: string;
}
export interface AllFilms {
allFilms: {
films: Film[];
};
}
const MY_QUERY = gql`
query AllFilms {
allFilms {
films {
id
title
releaseDate
}
}
}
`;
export interface MyViewProps {
name: string;
title: string;
}
const MyView = (props: MyViewProps): ReactElement => {
const { data, error } = useQuery<AllFilms>(MY_QUERY);
if (error) {
throw error;
}
return (
<MainLayout {...props}>
<h2>Films:</h2>
{data?.allFilms.films.map((film) => (
<ul key={film.id}>
{film.title} ({new Date(film.releaseDate).getFullYear()})
</ul>
))}
</MainLayout>
);
};
export default MyView;
nestjs-tsx-views can be configured with the following options:
export interface TsxViewsModuleOptions extends ReactViewsOptions {
/**
* The directory where your views (`.tsx` files) are stored. Must be
* specified.
*/
viewsDirectory: string;
/**
* [Doctype](https://developer.mozilla.org/en-US/docs/Glossary/Doctype) to
* be used. */
doctype?: string;
/**
* If activated, the generated HTML string is formatted using
* [prettier](https://github.com/prettier/prettier)
*/
prettify?: boolean;
/**
* With this optional function the rendered HTML document can be modified. For
* this purpose a function must be defined which gets the HTML `string` as
* argument. The function returns a modified version of the HTML string as
* `string`.
*/
transform?: (html: string) => string | Promise<string>;
/**
* Excludes routes from the currently processed middleware.
*
* @param {(string | RouteInfo)[]} routes
* @returns {MiddlewareConfigProxy}
*/
exclude?: (string | RouteInfo)[];
/**
* Attaches passed either routes or controllers to the currently configured middleware.
* If you pass a class, Nest would attach middleware to every path defined within this controller.
*
* @param {(string | Type | RouteInfo)[]} routes
* @returns {MiddlewareConsumer}
*/
forRoutes?: (string | Type<Controller> | RouteInfo)[];
}
nestjs-tsx-views is distributed under the MIT license. See LICENSE for details.
FAQs
Server-side JSX/TSX rendering for your NestJS application 🚀
The npm package nestjs-tsx-views receives a total of 339 weekly downloads. As such, nestjs-tsx-views popularity was classified as not popular.
We found that nestjs-tsx-views 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.