Follow the npm
steps
$ npm init
Add the dependencies:
$ npm install express redis redis-redisearch --save
Create the server.js
file and add the following code
const express = require('express')
const app = express()
const port = 3003
app.get('/api/1.0/', (req, res) => {
res.json({"status" : "started"});
})
app.get('/', (req, res) => {
res.send('RediSearch Node REST Server Started')
})
app.listen(port, () => {
console.log(`RediSearch Node listening at http://localhost:${port}`)
})
This will be the base of the various API endpoints.
In this sample application all the RediSearch interactions will be done in NodeSearchService.js
file.
You can run build and run the application from docker using the following commands:
Build
> docker build -t redis/search-backend-node .
This command will create a new image and build the Node.js project into it.
Run
> docker run --rm \
--env "REDIS_URL=redis://host.docker.internal:6379" \
--env "REDIS_INDEX=idx:movie" \
--name "redisearch-backend-node"\
-p 8086:8086 redis/redis-stack:latest
To run the application on your local machine:
> npm install
> npm start
You can now access the REST Search service using the following URL: