What is the correct way to utilize the wordcount function with the meteorhacks:npm package?

I recently added the meteorhacks/npm package to my Meteor app so that I could utilize the Wordcount package within it.

Unfortunately, I'm encountering difficulties with my method implementation.

On the client-side:

  getWordcount = function getWordcount(words, callback) {
    Meteor.call('getWordcount', words, callback);
  }

console.log(getWordcount('hello world')); // testing

On the server-side:

  Meteor.methods({
    'getWordcount': function getWordcount(words) {
      var WordcountApi = Meteor.npmRequire('wordcount');
      var wordcount = new WordcountApi({
          version: "1.1.1"
      });

      var words = Async.runSync(function(done) {
        wordcount.words, function(err, data) {
          done(null, data);
        }
      });

      return words.result;
    }
  });

The console is displaying an error message stating:

"Error invoking Method 'getWordcount': Internal server error [500]"

Answer №1

Here is my recommendation

Customer

// using a meteor method to retrieve word count and handling errors or results in a callback function
Meteor.call('calculateWordcount', 'hello world', function(err, results){
    if(err) console.error(err);
    else console.log(results);
});

Server Side

  Meteor.methods({
      'calculateWordcount': function calculateWordcount(words) {
          check(words, String);
          var wordcount = Meteor.npmRequire('wordcount');
          return wordcount(words);
      }
  });

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

What could be causing the npm start command to not function as expected?

After beginning a new project in React, I encountered an issue with npm start not functioning properly. While I was able to troubleshoot installation problems previously, this time I have tried multiple solutions without success. As I am unable to upload ...

Error: The request was denied by the operating system. Issue encountered while attempting to build a new React application

I recently installed the LTS version 14.17.3 of Node (npm version 6.14.13). Following that, I successfully globally installed create-react-app using the command "npm install -g create-react-app" (version 4.0.3). However, when attempting to create a new R ...

Hide popup in React Semantic UI when clicking on a different popup

I've integrated React Semantic UI into my application and I'm using the semantic Popup component to display tooltips. One issue I'm encountering is that when I click on a popup button, previously opened popups are not automatically closing. ...

The code 254 was unexpectedly returned by the command '/bin/sh -c npm install --silent'

While attempting to create an image of my React app with Docker, the following error message is displayed: The command '/bin/sh -c npm install --silent' returned a non-zero code: 254 Below is my dockerfile for reference: # Pull official base ...

The modal dialog from angular/material is unable to function properly when a shape on Google Maps is clicked

I have incorporated Google Maps into my application in order to showcase shapes (polygons/circles) and markers. To interact with Google Maps in Angular, I am utilizing the type definition "npm install --save @types/googlemaps". Upon clicking a shape, I nee ...

The children prop in React Typescript is specified in the props type, but for some reason it is not being

I am currently developing a component library using a combination of React, TypeScript, Styled Components, and Rollup. One of the components I have created is a Button component, defined using a type interface. After rolling up the library and importing th ...

What is causing the error to appear in the Android web-view when using vue.js?

During the development of my web app using Vue.js, I encountered a strange issue where everything was functioning correctly in desktop browsers but not on mobile devices. To troubleshoot this problem, I decided to install an Android emulator and use remote ...

Discovering indistinguishable "Feeling Fortunate" inquiries

My goal is to create a program on my website that can compare the top search results for different queries. For instance, I want it to recognize that the top search result for "twelve" and "12" is the same, leading to https://en.wikipedia.org/wiki/12_(numb ...

Encountered a 'node:internal/modules/cjs/loader:1146' error while setting up a React application

Encountering these console errors node:internal/modules/cjs/loader:1146 throw err; ^ Error: Module '../../package.json' not found Require stack: - C:\Users\adity\AppData\Roaming\npm\node_modules\npm\li ...

When utilizing auth0, an error occurs during the grunt build process

I successfully developed a small project using AngularJS on my local machine without encountering any issues. However, when I attempted to build the project with Grunt, everything stopped working and an error occurred: vendor.ce3c01a3.js:2 Error: [$inject ...

"Enhance the user experience by enabling clickable preview files in dropzone

After working on my Django project, I have implemented the following: <link href="{% static 'media/dropzone/dist/min/dropzone.min.css' %}" type="text/css" rel="stylesheet" /> <form class="dropzone" id="my-media-dropzone" action="/some/u ...

What is the method to change lowercase and underscores to capitalize the letters and add spaces in ES6/React?

What is the best way to transform strings with underscores into spaces and convert them to proper case? CODE const string = sample_orders console.log(string.replace(/_/g, ' ')) Desired Result Sample Orders ...

Leveraging Vue.js plugin within a single file component

I am looking to utilize the vue-chartkick plugin in my Vue application, but I want to register it within my single-file components instead of globally. Is there a way to achieve this same functionality without using Vue.use(VueChartkick, { Chartkick })? ...

What is the best way to include additional text in my scroll-to-top button that already features an icon?

I'm completely new to this industry, so I could really use some assistance. Despite trying every possible solution, nothing seems to be working for me. Currently, I am looking to add some text to my scroll-to-top button, which already exists with an ...

What is the method for retrieving the JSON data with the fetch API?

I'm currently stuck trying to access a JSON file called map.json using fetch(). Here's my code snippet: export function importJSON(url) { return fetch(url) .then(r => r.json()) .then(data => { return data; ...

I require integrating another element alongside this button

I am trying to create a button component that, when clicked, will display another component along with it. However, I am unsure of how to achieve this. Take a look at the plantioComp return - this is the component that I want the button to trigger. <t ...

Preventing conflicts while toggling visibility with JQuery across various groups

My navigation system allows me to show/hide divs and toggle an 'active' class on the navigation items. However, I've encountered conflicts when trying to use similar sections on the same page (clicking a link in one section affects divs in o ...

Tips for deactivating the highlight on a previously selected menu item when clicking on the next menu option in Angular.js

In my pages, I have a menu where the landing page menu is initially highlighted. However, when I move to the next menu, the previous landing page highlight remains instead of being removed while swapping the menu. I am using Angular.js and angular ui-route ...

What are the steps for transforming this code into pure CSS, or incorporating it into a Javascript function?

@function generate-random-box-shadows ($n) $value: '#{random(2000)}px #{random(2000)}px #FFF' @for $i from 2 through $n $value: '#{$value} , #{random(2000)}px #{random(2000)}px #FFF' @return unquote($value) $random-shadows1 ...

What is the process for accessing the content of a URI on the console page?

let request = new XMLHttpRequest(); request.open('GET', 'https://learnwebcode.github.io/json-example/animals-1.json'); request.onload = function() { console.log(request.responseText); }; request.send(); I am continuously seeing t ...