nats-memory-server
is a Node.js package that provides an in-memory NATS server for testing and other purposes. It allows you to quickly set up and tear down a NATS server instance within your Node.js applications, making it easier to write tests and perform other operations that require a NATS server.
- Lightweight and easy to use
- In-memory NATS server
- Suitable for testing and local development
- Zero configuration required
- Simple API for starting and stopping the server
- Supports NATS server options
- Go (version 1.19 or later)
You can install nats-memory-server
using npm or yarn:
npm install nats-memory-server
or
yarn add nats-memory-server
To use nats-memory-server
in your Node.js application, follow these steps:
- Import the package:
const NatsMemoryServer = require("nats-memory-server");
- Instantiate the server:
const server = await NatsMemoryServer.create();
- Start the server: if server already start this method throw error
await server.start();
- Connect your NATS client to the server:
const NATSClient = require("nats");
const nc = await NATSClient.connect({ servers: server.getUrl() });
-
Perform your tests or other operations using the connected NATS client.
-
Stop the server:
await server.stop();
That's it! Now you have an in-memory NATS server running for your application.
For more advanced usage and server options, please refer to the API documentation.
Contributions are welcome! If you find any issues or have suggestions for improvement, please feel free to open an issue or submit a pull request on the GitHub repository.
When contributing, please ensure to follow the code of conduct.
This project is licensed under the MIT License.