Code snippet of sails js, as seen on the homepage

I'm currently exploring sailsjs and trying out a simple example from their main page, but I keep encountering this error:

TypeError: socket.request is not a function
socket.request('/user', {}, function(users){ console.log(users); });

This is the code snippet causing the issue:

var socket = io.connect('http://localhost:1337');

    socket.on('connect', function (){
    socket.request('/user', {}, function(users){ console.log(users); });

    socket.on('message', function (message){
        console.log("Got message", message);
    });
});

Any assistance would be greatly appreciated!

Answer №1

Give this a shot

socket.fetch('/user', {}, function(userData){ console.log(userData); });

The socket module does not support the 'request' method, rather it offers the get and post functions which can be used to send requests to specific routes. In your scenario, if you are utilizing blueprints, a GET request will be made to the '/user' route triggering the 'find' method in your UserController.

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

Learning the art of dynamically injecting properties into an object using node.js

I need to dynamically add properties to an object based on the items in an array. Here is the initial object: const helpEmbedMsg = new global.Discord.MessageEmbed() .setColor("RANDOM") .setTitle("Help") ...

Check for the presence of an Outlook add-in within a web application

I'm having trouble determining whether my hosted web application is being accessed through a browser or from within the Outlook 2013/2016 client. I have developed a web application that offers different functionalities depending on whether it is acce ...

Sending parameters from one Node.js function to another in separate JavaScript files

I am currently working on passing function responses between two Node.js scripts. Here is my approach. Index.js var express = require('express'); require('./meter'); var app = express(); app.get('/',function(req,res){ ...

Scrolling Object Fixed (CSS)

I have a question that I need help with. I have some basic knowledge of CSS and jQuery, and I'm trying to add a Facebook like button to my webpage. My goal is to make the button stick to the top of the page when the viewer scrolls down, and return to ...

The message "The data format for the chart type is incorrect" pops up every time I try to input an array for a line graph

I am attempting to dynamically send array data to draw a chart. My goal is to receive input values [x and y] from the user using HTML. I have been successful in retrieving the data from HTML, but when I pass it to the chart, the format is not being recog ...

Adding a query parameter to my website causes a particular element to fail to display on the page

I'm facing a challenge in sharing my code, but since my project is open source, you can find the code here. I've noticed that when I receive a link from another site with /? at the end, it causes an issue on my website where the hero image secti ...

How can I prevent webpack from injecting eslint errors into my webpage?

Currently working with the Vue webpack project template and I've noticed that when the development server is running, any errors that occur are automatically injected into my webpage and also shown in the browser console. While I understand that this ...

How can IF and ELSE IF statements be used in JavaScript?

I am struggling to figure out the correct and efficient way to implement IF and else IF statements in javascript. Here is my current challenge... Currently, I am combining the values of 2 input fields and displaying them in another input field like this: ...

Switch up div containers with JavaScript based on the set array order of elements?

As I work on creating a list that calculates the sum of selected numbers, I encountered an issue with rearranging the items. Despite successful functionalities like adding images with names, changing languages, and performing calculations, the page keeps r ...

HTTP request in Angular with specific body content and custom headers

My goal is to access the sample API request from , as demonstrated in the documentation: curl -H "api-key: 123ABC" \ -H "Content-Type: application/json" \ -X POST \ ...

Adjust the height of a div in JQuery to fit new content after specifying a height previously

I have a division element with an initial height of 0 and opacity set to zero, its overflow is hidden, and it contains some content. <div style='height: 0px; opacity: 0px; display: none; overflow: hidden; border: 1px solid #000;' id='myd ...

What is the best way to retain all form filters after reloading the view in Laravel 5.4?

The form below is the one I have in view: <form class="form-inline" method="POST" action="{{route('dsp.report')}}"> @csrf <!-- {{ csrf_field() }} --> <div class="col-sm-2 form-group"> ...

Develop a GWT overlay specifically designed for a deeply nested JSON data structure

Recently stumbling upon this amazing site, I find myself compelled to seek your assistance with a particular issue: How do you go about accessing the fields within the nested JSON object labeled "flightLegs" from the main JSON object "flights"? When it c ...

Swapping React components within a list: How to easily change classes

For my latest project, I am building a straightforward ecommerce website. One of the key features on the product page is the ability for users to select different attributes such as sizes and colors. These options are represented by clickable divs that pul ...

Error message "Unable to load / invalid sound with zero-length duration reported on Chrome and Firefox."

Encountered an issue where / invalid sound zero-length duration was reported in Chrome and Firefox. However, the error only appeared in IE10. Here is the code snippet: foo = soundManager.createSound({ id: 'bar', url: '../music/ ...

Using Vue.js with the slot-in attribute

Looking to create a unique vue.js template that functions as described below: <CustomComponent></CustomComponent> should produce <div class="a"></div> <CustomComponent>b</CustomComponent> should result in <div class ...

Exploring the power of regular expressions in Javascript when used between

Consider the scenario outlined in the text below I desire [this]. I also desire [this]. I do not desire \[this] I am interested in extracting the content enclosed within [], but not including \[]. How should I approach this? Currently, I have ...

`Why my React function calls are not being tested properly with Jest and Sinon?`

I need help determining how many times my React class method is executed after an event. I've experimented with sinon.spy and jest.fn() but haven't had success. Attempt using sinon.spy: test('Example test', (done) => { const page ...

What is the JavaScript method for updating an HTML5 datalist to show new options?

When populating options dynamically into an HTML5 datalist, I'm facing an issue where the browser tries to display the datalist before all the options have loaded. As a result, the list either does not show up completely or only partially shows up. Is ...

Obtaining the chart object within a point event function in Highcharts can be achieved by accessing the

Is there a way to modify the code below so that I can retrieve the value of the point in the first series even when clicking on a point in the second series? I only need access to the chart object, but I'm not sure how to achieve this since within the ...