I'm getting "typesense is not defined" whenever I ...
# community-help
t
I'm getting "typesense is not defined" whenever I try to run... I followed everything in the Install/configure guide...
m
Could you paste your codes?
t
var fs = require('fs'); var readline = require('readline'); let client = new Typesense.Client({     'nodes': [{       'host': 'localhost',       'port': '8108',       'protocol': 'http'     }],     'apiKey': '<API_KEY>',     'connectionTimeoutSeconds': 2   }) let booksSchema = {     'name': 'books',     'fields': [         {'name': 'title', 'type': 'string' },         {'name': 'authors', 'type': 'string[]' },         {'name': 'image_url', 'type': 'string' },         {'name': 'publication_year', 'type': 'int32' },         {'name': 'ratings_count', 'type': 'int32' },         {'name': 'average_rating', 'type': 'float' },         {'name': 'authors_facet', 'type': 'string[]', 'facet': true },         {'name': 'publication_year_facet', 'type': 'string', 'facet': true },     ],     'default_sorting_field': 'ratings_count' } client.collections().create(booksSchema)   .then(function (data) {     console.log(data)   }) readline.createInterface({     input: fs.createReadStream('./books.jsonl'),     terminal: false }).on('line', function(line) {    let bookDocument = JSON.parse(line);    client.collections('books').documents().create(bookDocument) }); let searchParameters = {     'q'         : 'harry',     'query_by'  : 'title',     'sort_by'   : 'ratings_count:desc'   }      client.collections('books')     .documents()     .search(searchParameters)     .then(function (searchResults) {       console.log(searchResults)     })
I literally used the example code
m
Did you run
npm i
in your working director?
t
yes
i did npm install --save typesense
m
where is your typesense import?
import Typesense from 'typesense'
j
@Tim Jang Echoing what Masahiro said, you want to add either an import statement or require statement to get that block of code to work.
Looks like that line of code is missing in the snippet in the docs, I'll add that in shortly
I've added it now
👏 1