Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@nestjs/websockets
Advanced tools
@nestjs/websockets is a module for the NestJS framework that provides WebSocket capabilities. It allows developers to create real-time, event-driven applications using WebSockets, which are essential for applications requiring instant data updates, such as chat applications, live notifications, and online gaming.
WebSocket Gateway
This feature allows you to create a WebSocket gateway that listens for incoming WebSocket connections and messages. The `@WebSocketGateway` decorator is used to define a WebSocket gateway, and the `@SubscribeMessage` decorator is used to handle specific message events.
```typescript
import { WebSocketGateway, WebSocketServer, SubscribeMessage, MessageBody } from '@nestjs/websockets';
import { Server } from 'socket.io';
@WebSocketGateway()
export class ChatGateway {
@WebSocketServer()
server: Server;
@SubscribeMessage('message')
handleMessage(@MessageBody() message: string): void {
this.server.emit('message', message);
}
}
```
WebSocket Client
This feature allows you to create a WebSocket client that can connect to a WebSocket server. The `@WebSocketClient` decorator is used to define a WebSocket client, and the `OnGatewayInit`, `OnGatewayConnection`, and `OnGatewayDisconnect` interfaces are used to handle client lifecycle events.
```typescript
import { Injectable } from '@nestjs/common';
import { WebSocketClient, OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect } from '@nestjs/websockets';
import { Socket } from 'socket.io-client';
@Injectable()
@WebSocketClient()
export class ChatClient implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
private client: Socket;
afterInit(client: Socket) {
this.client = client;
console.log('WebSocket client initialized');
}
handleConnection(client: Socket) {
console.log('Client connected:', client.id);
}
handleDisconnect(client: Socket) {
console.log('Client disconnected:', client.id);
}
}
```
Custom WebSocket Server
This feature allows you to create a custom WebSocket server using the `ws` library. The `@WebSocketGateway` decorator can accept a custom server instance, and you can handle connection and message events directly.
```typescript
import { WebSocketGateway, WebSocketServer } from '@nestjs/websockets';
import { Server } from 'ws';
@WebSocketGateway({ server: new Server({ port: 8080 }) })
export class CustomGateway {
@WebSocketServer()
server: Server;
constructor() {
this.server.on('connection', (socket) => {
socket.on('message', (message) => {
console.log('Received message:', message);
});
});
}
}
```
Socket.IO is a popular library for real-time web applications. It enables real-time, bidirectional, and event-based communication between web clients and servers. Compared to @nestjs/websockets, Socket.IO is more general-purpose and can be used with various frameworks, while @nestjs/websockets is specifically designed for use with the NestJS framework.
The `ws` package is a simple and fast WebSocket library for Node.js. It provides a bare-bones WebSocket server and client implementation. Compared to @nestjs/websockets, `ws` is lower-level and requires more manual setup, whereas @nestjs/websockets provides a more integrated and higher-level API within the NestJS framework.
A progressive Node.js framework for building efficient and scalable server-side applications.
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses modern JavaScript, is built with TypeScript (preserves compatibility with pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
Under the hood, Nest makes use of Express, but also, provides compatibility with a wide range of other libraries, like e.g. Fastify, allowing for easy use of the myriad third-party plugins which are available.
In recent years, thanks to Node.js, JavaScript has become the “lingua franca” of the web for both front and backend applications, giving rise to awesome projects like Angular, React and Vue which improve developer productivity and enable the construction of fast, testable, extensible frontend applications. However, on the server-side, while there are a lot of superb libraries, helpers and tools for Node, none of them effectively solve the main problem - the architecture.
Nest aims to provide an application architecture out of the box which allows for effortless creation of highly testable, scalable, loosely coupled and easily maintainable applications. The architecture is heavily inspired by Angular.
For questions and support please use the official Discord channel. The issue list of this repo is exclusively for bug reports and feature requests.
Please make sure to read the Issue Reporting Checklist before opening an issue. Issues not conforming to the guidelines may be closed immediately.
With official support, you can get expert help straight from Nest core team. We provide dedicated technical support, migration strategies, advice on best practices (and design decisions), PR reviews, and team augmentation. Read more about support here.
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support from the amazing backers. If you'd like to join them, please read more here.
Nest is MIT licensed.
FAQs
Nest - modern, fast, powerful node.js web framework (@websockets)
The npm package @nestjs/websockets receives a total of 347,448 weekly downloads. As such, @nestjs/websockets popularity was classified as popular.
We found that @nestjs/websockets demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.