Getting the Hostname in a NestJS Controller Function

I am currently utilizing a NestJS application to serve a REST-API.

Is there a way for me to obtain the current Hostname within a controller?

This is my controller function:

async find(@Param('uuid') uuid: string, @Req() req: Request): Promise<BlogDto> {}

I am able to view the Path in the URL by using:

console.log(req.url);

However, I am unsure about how to determine the current hostname of my application.

I came across examples like this one, but it does not work because there is no Get-method on the Request-Headers-Object:

console.log(req.headers.get('host')); // not existing

Answer №1

Employing the @Headers decorator, I have utilized it to retrieve the host header:

@Headers('host') host: string

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 specific design scheme is employed in the MEANJS project?

After transitioning from PHP to NodeJs and working on a MEANJS project, I encountered an issue where I couldn't use a controller method in another controller. It seems like I may have followed the wrong pattern. student.model.js ----------------- var ...

Issue: Trying to access a property called 'name' on an undefined variable in NodeJS

I'm currently experiencing an issue with the post statement in Node.js and have been struggling to find a solution. The error message I am encountering is as follows: TypeError: Cannot read property 'name' of undefined at C:\x&bsol ...

Sending both files and JSON data in a single request using the express framework in Node.js

Below is the JADE form: <form id="formAddchallandetails" action="/adddata" method="post" name="adduser"> <input id="inputunloadingDestination1" type="text" name="finalchallan[1][unloadingDestination]" placeholder="unloading Destination"> ...

the pause in execution before my function redirects to a different route

Currently, I am developing a page using nodeJs with express which is supposed to display a table. However, I encountered an issue with my variable "allMusique" that contains the data for my page. When trying to access it initially, there seems to be an err ...

The loading of npm installed Firebase in Angular4 is not successful

I am currently facing an issue while trying to integrate npm installed Firebase with my Angular4 application. I have successfully installed the latest version of Firebase (version 4.1.1) using npm and verified that the installation was successful. Below is ...

Having trouble with the POST method in my Node.js application, and I'm unsure of the cause

This is the main index.js file that serves as the entry point for my Node.js application. const express = require('express'); const app = express(); const path = require('path'); const port = process.env.PORT || 2000; require('./db ...

Systemd Debian Autorun Service: Optimizing Your System Startup

I've been working on a node.js App. Currently, in the directory (/var/lib/cloud9/BBB_WebApp$), there's a package.json: { "name": "MCP", "version": "0.0.0", "private": true, " ...

Getting JSON object string in Node.js using Express

I am currently utilizing Polymer's <iron-ajax> to send data, in the form of a JSON string created using JSON.stringify, to a Node Express server. However, upon receiving the data, it appears in a strange format that I am unable to parse. Specifi ...

What is the most efficient way to ensure every dependency in package.json is updated to the most recent version available

I recently brought over the package.json file from another project and now I want to update all of the dependencies to their latest versions since this is a new project and I'm willing to troubleshoot any issues that may arise. Is there an easy way t ...

Encountering an error when creating LevelDB with NodeJS

Attempting to access a database using the following code: const LevelUP = require('levelup'); const LevelDown = require('leveldown'); const path = require('os').homedir() + '/keys.db'; const db = LevelUP(LevelDow ...

Having trouble establishing a connection to the remote server using node js?

I have been working on integrating a third-party Recharge API. I provided them with the necessary URL, so that whenever a message is sent - whether it's a success or failure - they can update the URL accordingly. Upon checking my AWS system, everythi ...

Utilize NestJS to retrieve information from an observable gRPC service

One of the challenges I am facing is using gRPC service to facilitate communication between my microservices. Specifically, when receiving a response from the Grpc service, I need to apply some modifications and additional functionality before returning a ...

Can you explain the purpose of having module.exports = function(app)?

Can you clarify the significance of the following codes? I would appreciate an explanation for all three lines. module.exports = function(app){ var x = express.router(); var y = express.router(); } I have tried researching these codes online, ...

The Unexpected Flash: Troubleshooting an AJAX Request Gone Awry in CompoundJS

I am attempting to utilize the flash('error', 'error text') function in order to notify the webpage of any errors that may occur during an ajax request. The ajax request accesses an action that involves working with a database, making i ...

What is the best way to interact with Redis without using any external modules?

I am curious about the communication process between the node redis wrapper and the RESP (REdis Serialization Protocol) database. Here is a simple example: const redis = function(uri) { this.client = '' // How do we establish a connection wit ...

The functionality is verified in Postman, however, it is not functioning properly when accessed from my client's end

I am working on a project where I have a button in my client's application that is supposed to delete a document from a MongoDB collection based on its ID. Here is the backend code for this functionality: index.js: router.post('/deletetask' ...

Elastic Beanstalk on AWS is unable to install a private Node.js module that is hosted on Bitbucket

Attempting to launch a node.js application on Elastic Beanstalk. The main package.json contains a private module hosted on Bitbucket. "dependencies": { "my-module": "git+https://<API-KEY>:<a href="/cdn-cgi/l/email-protection" class="__cf_email_ ...

Encountering a Caution Message When Attempting to Install Yeomen

Upgrade to a higher version is recommended at [email protected], but how should I proceed? Please provide guidance on achieving this upgrade. C:\Program Files>npm install -g yo npm WARN deprecated <a href="/cdn-cgi/l/email-protection" clas ...

Upgrade the package to the latest major version using NPM

When working on a Node.js project, the process of upgrading a package to a major release may seem unclear at first glance. For example, let's say I want to install stylelint: npm install --save stylelint By default, this command adds "stylelin ...

The free version of Neo4j and Linkurious for the community

Is it possible to integrate linkurious.js community edition with Neo4j? I have heard about the sigma-parser-cypher plugin. As a beginner in both Neo4j and Linkurious, your patience is appreciated. Can both Linkurious JS and Neo4j be run on the same machi ...