Creating classes in an Express controller using CoffeeScript is essential for organizing and structuring your code

I have a controller named

api/meeting/meeting.controller.coffee

class Talker
  constructor: (@name) ->
    talk: ->
      console.log "Talker name is" + @name

module.exports.meeting = (req, res, next) ->
  talker = new Talker 'Bob'
  talker.talk

This is how I reference the above file in my index.coffee

 controller = require './meeting.controller'
 router.post('/', controller.meeting );

The wiring is done in routes.js:

`app.use('/meeting/',      require('./api/meeting'));`

Although the wiring and routing are functioning properly, the console.log from the class isn't being displayed in my CLI. Any suggestions on how to resolve this issue?

Answer №1

There was an issue with indentation and a method call error that was causing some trouble. Here is how the code should look:

class Speaker
  constructor: (@name) ->
  speak: ->
    console.log "Speaker's name is" + @name

module.exports.presentation = (req, res, next) ->
  speaker = new Speaker 'Alice'
  speaker.speak()

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

Tips on utilizing a single controller for two identical views in AngularJS

I'm currently implementing Angular seed in my project. I am facing a situation where I have two identical views (HTML pages) with the same elements and functionality. Both pages contain a GridView that needs to be populated by the same service, but th ...

What is the best way to add elements using JavaScript when a particular character is present?

Current: <p id="article">忙著端出 高階 DSLR 產品的 Nikon ,總算想到了在 兩年半之後 更新自己的入門系列數位單眼相機,端出 Nikon D3400。很好的產品</p> I want to divide the text whenever certain charac ...

Positioning a div on the right side of its parent div

Hi there! I'm currently working on a small navbar that has two sections: the left section with an arrow icon and the right section with two icons - an envelope and an exclamation triangle. I've been trying to position the right section in the top ...

What is the best way to trigger a jQuery UI dialog using an AJAX request?

My website includes a jQuery UI Dialog that opens a new window when I click the "create new user" button. Is there a way to open this window using an AJAX request? It would be useful if I could open the dialog-form from another page, such as dialog.html ...

Uploading an image along with additional information to Strapi using React

Can you assist me with allowing users to post data on Strapi, such as their name, URL, description, and image? I attempted to add an input type file but encountered a 500 error. I suspect this could be due to the need to call localhost:1337/upload, but I& ...

Node and Express - A dynamic tool for managing resources specific to each route

I've stumbled upon several asset managers designed for node and express: connect-assets, bundle-up, node.packer, node-static-asset However, they all seem to use only one configuration for serving concatenated and minified assets in production. Does ...

Ensure that the request is authenticated before redirecting to the static folder with Express JS

I have a web application written in JavaScript located in the public folder. Before granting users access to this folder, I want to verify the requests using express middleware. Here's the project structure : |__app.js |__routes |__root.js |__pub ...

What is the process for choosing every child (regardless of level) of a parent using jQuery?

Is there a way to unbind all elements from a parent node using jQuery? How can I effectively select all children, regardless of their nesting level, from a parent node? I attempted the following: $('#google_translate_element *').unbind('c ...

React hooks: Unable to modify state within functional component

Exploring the realm of React, I've embarked on a journey to create a digital phonebook. Progress has been made, but alas, an elusive challenge remains unresolved in my use of React Hooks. All seems well until the moment I invoke the setNewNumber(&apo ...

Preserve a retrieved value from a promise in Angular

Upon loading the page, the dropdown menu is populated with various values (such as 1, 2...7). However, when attempting to set a specific value based on a certain condition within a promise, it doesn't seem to work. How can this issue be resolved? htm ...

The browser unexpectedly cancelled the ajax call triggered by the beforeUnload event

Seeking advice on a web application that needs to save user input data through an ajax call when they leave the site. Currently using "Fetch" in a beforeunload event listener, but encountering issues with browsers cancelling the ajax call (specifically th ...

Leverage user input to perform various calculations within a component

Struggling to make use of a user-supplied number for multiple computations within a component. The input is successfully utilized in the initial calculation for deckboards, but subsequent calculations such as joists (newArea / 0.45) fail to produce any o ...

What is the best way to modify the colors of two specific elements using a combination of CSS and JavaScript

I am currently developing a browser-based game and have encountered an issue. Here is the relevant line of my HTML/PHP code: echo '<div id="div'.$n.'" class="d'.$rand.'" onclick="swapit(this.id, this.className)"></di ...

Is there a way to create a "navigate to" button directly from the text within a <p> element?

Within my HTML, there is a <p> tag which dynamically receives a link value from a JavaScript function. The link could be anything from www.google.com to youtube or instagram. How can I utilize the "copytoclipboard" library to copy this link to clipbo ...

Tips for utilizing a unique JavaScript function with Mongoose's findByIdAndUpdate by incorporating $set:

Is it possible to update a database document using a custom JavaScript function? I am aware of the traditional method where you find -> update the document with JavaScript -> save, but this can lead to issues with concurrent data updates. Below is an ...

Looping through an array of images using JavaScript

Currently, I have a computer science test at school, and the main question is to create a traffic light that changes colors in a loop using arrays. I am facing some challenges with this question, but I believe I am close to solving it. Below is my code sni ...

Replace Formik with useFormik to streamline your code

I have implemented Formik/Yup for validation on a page that triggers a GraphQL mutation. The code is functioning as expected: export default function RemoveUserPage() { const [isSubmitted, setIsSubmitted] = useState(false); const [isRemoved ,setIsRemo ...

Permanently dismiss Bootstrap 4 alert using a cookie

Recently, I came across a bootstrap 4 alert that I found quite useful. Here is the code snippet for it: <div class="alert alert-warning alert-dismissible fade show" role="alert"> <button type="button" class="clo ...

The backend is not receiving any data from the JS post call

Attempting to transfer login data from the front end to mongodb. The JavaScript file takes the id and password values from the pug file and initiates a post call, sending the login id and password. The route /postlist then receives the values and display ...

Tips for maintaining the nested collapsible table row within the main table row in a React MUI table

I am working on implementing a Material UI (MUI) table that includes collapsible table rows. The challenge I am facing is maintaining consistent border and background colors across all the rows, even when some are collapsed. Currently, the separate rows ar ...