https://github.com/redis-developer/redis-starter-js
A starter project for working with Redis and JS
https://github.com/redis-developer/redis-starter-js
express javascript js node-redis redis starter template
Last synced: 11 months ago
JSON representation
A starter project for working with Redis and JS
- Host: GitHub
- URL: https://github.com/redis-developer/redis-starter-js
- Owner: redis-developer
- Created: 2024-11-01T16:49:51.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-28T19:28:03.000Z (12 months ago)
- Last Synced: 2025-02-28T22:59:26.583Z (12 months ago)
- Topics: express, javascript, js, node-redis, redis, starter, template
- Language: JavaScript
- Homepage: https://redis.io/docs/latest/develop/clients/nodejs/
- Size: 308 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This is a [Redis](https://redis.io/) starter template for JS and [Node](https://nodejs.org/) using:
- [Redis Cloud](https://redis.io/try-free/)
- [Express](https://expressjs.com/)
## Requirements
- [bun](https://bun.sh/)
- [docker](https://www.docker.com/)
- Optional
## Getting started
Copy and edit the `.env` file:
```bash
cp .env.example .env
```
Your `.env` file should contain the connection string you copied from Redis Cloud.
Your `.env.docker` file will look similar to `.env`, but should use the appropriate docker internal URLs. Here is
an example:
```bash
REDIS_URL="redis://redis:6379"
```
Next, spin up docker containers:
```bash
bun docker
```
You should have a server running on `http://localhost:` where the port is set in your `.env` file (default is 8080). You can test the following routes:
1. `GET /api/todos` - Gets all todos
2. `GET /api/todos/:id` - Gets a todo by ID
3. `GET /api/todos?[name=]&[status=]` - Search for todos by name and/or status
4. `POST /api/todos` - Create a todo with `{ "name": "Sample todo" }`
5. `PATCH /api/todos/:id` - Update todo by ID with `{ "status": "todo|in progress|complete" }`
6. `DELETE /api/todos/:id` - Delete a todo by ID
## Running tests
There are some tests in the `__tests__` folder that can be run with the following command:
```bash
bun test
```
These tests setup and teardown on their own. You can modify them if you want to leave data in Redis.
## Running locally outside docker
To run the development server outside of docker:
```bash
bun install
# then
bun dev
```
## Other Scripts
Formatting code:
```bash
bun format
```
Updating dependencies:
```bash
bun update
```
## Connecting to Redis Cloud
If you don't yet have a database setup in Redis Cloud [get started here for free](https://redis.io/try-free/).
To connect to a Redis Cloud database, log into the console and find the following:
1. The `public endpoint` (looks like `redis-#####.c###.us-east-1-#.ec2.redns.redis-cloud.com:#####`)
1. Your `username` (`default` is the default username, otherwise find the one you setup)
1. Your `password` (either setup through Data Access Control, or available in the `Security` section of the database
page.
Combine the above values into a connection string and put it in your `.env` and `.env.docker` accordingly. It should
look something like the following:
```bash
REDIS_URL="redis://default:@redis-#####.c###.us-west-2-#.ec2.redns.redis-cloud.com:#####"
```
Run the [tests](#running-tests) to verify that you are connected properly.
## Learn more
To learn more about Redis, take a look at the following resources:
- [Redis Documentation](https://redis.io/docs/latest/) - learn about Redis products, features, and commands.
- [Learn Redis](https://redis.io/learn/) - read tutorials, quick starts, and how-to guides for Redis.
- [Redis Demo Center](https://redis.io/demo-center/) - watch short, technical videos about Redis products and features.