What's the deal with this error message saying val.slice isn't a function?

In the process of developing a web application using express with a three-tier architecture, I have chosen to use a mysql database to store blogposts as a resource. Here is an illustration of how the table is structured:

CREATE TABLE IF NOT EXISTS blogposts (
    blogId INT NOT NULL AUTO_INCREMENT,
    title VARCHAR(255) NOT NULL,
    content VARCHAR(255) NOT NULL,
    posted VARCHAR(255) NOT NULL,
    imageFile VARCHAR(255) NOT NULL,
    userId INT NOT NULL,
    CONSTRAINT blog_id PRIMARY KEY (blogId),
    CONSTRAINT id_fk FOREIGN KEY (userId) REFERENCES accounts(personId)
);

My current objective is to retrieve a specific blogpost ID by sending queries to the database through the data access layer. The function for this operation looks like this:

exports.getBlogpostId = function(blogId ,callback){

    const query = "SELECT * FROM blogposts WHERE blogId = ?"
    const value = [blogId]
    db.query(query, value, function(error, blogpost){
        if(error){
            callback("DatabaseError", null)
        }else{
            callback(null, blogpost)
        }
    })
}

After implementing it in the business logic layer:

exports.getBlogpostId = function(callback){
    blogRepo.getBlogpostId(function(blogpost, error){
        callback(error, blogpost)
    })
}

Finally, utilizing it in the presentation layer:

router.get("/:blogId", function(request, response){

    const blogId = request.params.blogId
    blogManager.getBlogpostId(blogId, function(error, blogpost){

        const model = {
            error: error,
            blogpost: blogpost[0]
        }
        response.render("blogpost.hbs", model)
    })
})

However, upon attempting to retrieve the ID, an error surfaced:

TypeError: val.slice is not a function
      at escapeString (/web-app/node_modules/sqlstring/lib/SqlString.js:202:23)
      at Object.escape (/web-app/node_modules/sqlstring/lib/SqlString.js:56:21)
      at Object.format (/web-app/node_modules/sqlstring/lib/SqlString.js:100:19)
      ...

Despite not specifically calling the slice method, the error persisted. Why might this occur?

UPDATE: The issue was identified - I had neglected to include blogId as a parameter in the business logic layer!

Thank you for any assistance provided!

Answer №1

Upon examination, it appears that the error is originating from the sqlstring module, specifically within the context of

/web-app/src/pl/routers/blogRouter/blogRouter.router.js:39:17
. It is imperative to investigate this section for further insights.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Organizing Angular Material Styles using Namespacing

In an attempt to develop reusable components with Angular 1.4.3 and Angular-Material 1.0.5, the goal is to seamlessly integrate these components across various applications. However, a challenge arises as the Angular Material CSS contains styling rules th ...

Can a MYSQL query be created to join multiple tables where the values of one table column are used as separate query columns?

I am looking to merge multiple tables in order to create a CSV file that our backoffice system can interpret. One table contains Product information, while another table contains language information. The structure of the databases is as follows: Product ...

Leveraging regex match.map to incorporate a React <img> tag within a given string

One of my recent discoveries involves replacing a string completely with React image elements, as demonstrated in the following code snippet: if (source.match(/\{([0-z,½,∞]+)\}/g)) { tagged = source.match(/\{([0-z,½,∞]+)\ ...

Guide on extracting data from an HTML table column and saving it to a JavaScript array with the help of JQuery

Suppose there is a table column containing 10 rows, each with <td id="num"> and some text value. Is there a way to utilize JQuery in order to iterate through every row within the column and store the values in a JavaScript array? I attempted the co ...

Is it possible to trigger a textbox text change event after autocompleting using jQuery

I recently implemented a jquery autocomplete plugin for a textbox: $('#TargetArea').autocomplete({ source: '@Url.Action("GetTarget", "Ads", new { type = "Zip", term = target })' }); The implementation is working as expected. ...

Error: Certain Prisma model mappings are not being generated

In my schema.prisma file, I have noticed that some models are not generating their @@map for use in the client. model ContentFilter { id Int @id @default(autoincrement()) blurriness Float? @default(0.3) adult ...

Resetting an object back to its initial value while preserving its bindings in AngularJS

My service deals with a complex object retrieved from an API, like this: { name: "Foo", addr: { street: "123 Acacia Ave", zip: "10010" } } The initial value is stored in myService.address, and another variable holds a copy of ...

Launching a web application directly from a USB drive

Exploring the world of Javascript frameworks and nodejs, I recently encountered a unique requirement that got me thinking about their practical application. The requirements are as follows: --I need to create a lightweight website that can be run from a U ...

iOS devices featuring the scroll function allows for seamless navigation and effortless

Here is the code snippet that I am using: $(document).scroll(function() { thedistance(); }); I would like thedistance() to trigger while a user is scrolling on an iOS device, however, it currently only fires after the scrolling has stopped, rather t ...

Transition not influencing the scale property when activating a class

My modal is not scaling in and out properly when I toggle the 'active' class. It either fully scales out or scales in without any transition. Example: const openPopupButtons = document.querySelectorAll('[data-popup-target]'); const ...

Typescript Regular Expression Issue: filter function is not returning any matches

Currently, I am developing an Ecommerce API and working on a class specifically for search queries. My approach involves using regex and typescript with node.js. Although I have based my project on a JavaScript node project, I am encountering an issue wher ...

Identify modifications to properties in Angular

What is the most effective method for responding to property changes within a component? I am seeking a solution that will trigger a specific function every time a property in a component is altered. Consider the following example with a single component: ...

Issue: Unable to locate package '@heroku/buildpack-registry'

I'm facing an issue while attempting to deploy a web app on Heroku. The error message I'm encountering is as follows: Error: Cannot find module '@heroku/buildpack-registry' I have already tried specifying the version of node I am using, ...

Use radio buttons to enable switching between different data options within a dropdown menu

I am working on a dropdown box that is populated dynamically using JSON data. The content in the dropdown can be categorized into 4 types, so I have included radio buttons to switch between these categories. I have created HTML code to toggle between manu ...

Experiencing difficulties when attempting to send an SMS to a phone number through MessageBird

When attempting to send a test SMS, I encountered an error in the first line of code stating that require(...) is not a function. Here is the code snippet: const messagebird = require('messagebird')('<YOUR_ACCESS_KEY'); var messageO ...

Unable to retrieve a substring value in Angular using Typescript

html <p> <input type="text" maxlength="40" (input)="recipientReference = deleteSpacing(recipientReference)" [(ngModel)]="recipientReference" style="width: 30vw; padding: 5px;border: 1px solid;border ...

I noticed that the node_modules folder has mysteriously vanished from my

When I tried running npm install in the terminal of VS Code. PS D:\work\backEnd> npm install npm WARN old lockfile npm WARN old lockfile The package-lock.json file was created with an older version of npm, npm WARN old lockfile so ...

Textfield with predictive text suggestions

I am currently working on implementing an autocomplete textfield for my Rails application, following the example from the Agile Web Development with Rails, 3rd Edition. However, when I try to insert their demo code: <%= stylesheet_link_tag &apo ...

Create a new chart using completely unique information

I am currently working on implementing the example found at http://bl.ocks.org/mbostock/1093130. The goal is to have the "update" function redraw the graph with a completely different dataset each time a button on the DOM is pressed. I have made some modif ...

Using Node.js to create a RESTful API that pulls information from MongoDB

I am currently working on creating a REST API using Node.js to retrieve the last N rows from a MongoDB collection. Here is my current code snippet: var express = require("express"); var app = express(); var bodyParser = require("body-pa ...