i am a new software developer. I don't have much software background, but I'm trying to learn as much as I can. Is there anyone who has done influxdb operation with nestjs before? If yes, can you share your previous experiences?
Thank you in advance for reading and replying.
Your going to face many hardships if you consider using nestjs... Maybe im wrong and your underselling yourself, but if you are asking if its possible to connect a database to your backend then nest is surly going to be WAYYYYY WAYYYYY WAYYYYY to complex -> to be able to figure stuff out... Not that you CANT but you might want to consider
Express first just to get an understanding of how a backend works -> without having to plan out all your dtos' controllers services yatta yatta yatta.. you can do all of the same stuff with express, infact the developers used express to make next -> and then added a whole lot of enterprise level stuff that doesnt come standard with express.
plus if you are new to coding then typescript might be a bit much. very sorry if this was not what you were looking for Im not trying to steer you in any particular direction. but I spend 12 hours - 36 hours sometimes trying to figure things out that I already had working before ... the injection and all that come with nest is good , but if you dont know why you need it , then its going to be very hard to actually learn the concepts.
its alot easier to teach someone how to drink water if theyre thirsty .
otherwise you are just going to spend alot of time that could of went into learning the things that are a prerequisite of nest
strong es6 / ts is def a must
the es6 part is more important imo because dealing with everything async for instance and the way everything is formatted its very confusing without a strong grasp of whats going on behind the scenes.
--- as im sure your going to want to find out the hard way -> and i dont blame you if you can get through it you will be a much stronger person =) but here try this on for size.
https://www.npmjs.com/package/nest-influxdb
import { Module } from "#nestjs/common";
import { InfluxDbModule, InfluxModuleOptions } from "nest-influxdb";
import { UtilsModule } from "./utils/utils.module";
import { ConfigService } from "./utils/config/config.service";
#Module({
imports: [
InfluxDbModule.forRootAsync({
imports: [UtilsModule],
inject: [ConfigService],
useFactory: async (
config_servie: ConfigService
): Promise<InfluxModuleOptions> => {
return {
host: config_servie.get("INFLUX_HOST")
};
}
}),
BlogModule
],
controllers: [AppController],
providers: [AppService]
})
export class AppModule {}
this will go in your root level module file -> then you will use the for feature method for the specific thing inside your root database
check the nest docs for how it works with other databases then try to connect the dots with that above package
Related
I am trying to use a nodejs library like uuid in my typescript app. This simple import works just fine if I want to only use it in a specific class:
import { v4 } from "uuid";
class MyClass {
...
}
However, this makes the class MyClass not "discoverable" by any other files in my solution. Sure I could export it, but that forces me to import the class in every usage, and the problem spreads like a cancer to every file. Do I really have to import/export every single class/file in my application just because I want to produce a simple UUID?
I saw that I can use require instead, however typescript doesn't know what that keyword is. I found this question but neither installing #types/node nor the quick and dirty declare var require any works.
It really seems like I am jumping through a lot of unnecessary hoops just to generate a uuid in typescript. Am I doing something very wrong?
Thanks
I apologize for what is likely a very amateur question. Coming from Laravel, this is still quite confusing to me and I just don't understand what is needed.
I have a user.repository.ts file and a location.repository.ts file. Each have their own modules, controllers and services. I have successfully created CRUD operations for each entity but now am trying to work towards a Many to Many relationship.
In my user.repository.ts file, I am trying to save a related (many to many) repository:
// user.repository.ts
user.locations = await this.locationRepository.findByIds(locations);
...
await user.save();
I am not sure how to inject or import the location.repository.ts file. I have tried numerous variations of importing the service into each module. Or importing each module into the other module. I have tried different versions of this:
#EntityRepository(User)
#EntityRepository(Location)
Or importing the LocationService into the UserService.
In Laravel, this would be as "simple" as $model->sync($relationship);
How can I import/inject the locationRepository into my userRepository? Thank you for any suggestions!
I assume this question is related to your last question, the simplest way to implement it, Add Locationentity to your UserModule
#Module({
imports:[TypeOrmModule.forFeature([UserRepository,LocationRepository])], // or just Location entity [UserRepository,Location] if you didn't setup a custom LocationRepository
After that, inject it in your as what you did for userRepo... service
constructor(
#InjectRepository(LocationRepository)
private locationRepository: LocationRepository,
// or just private locationRepository: Repository<Location>,
) {}
In the create method service get your locations:
async createUser(createUserDto: CreateUserDto) { // usersSrvice
let locations = await this.locationRepository.findByIds(createUserDto.locations);
await this.userRepository.createMethodeName(createUserDto,locations) // add secand
params for your locations
don't hesitate to ask if you have any other questions
I was searching the internet for hours on end hoping to find any kind of built-in functionality to support byte-range requests (https://www.keycdn.com/support/byte-range-requests) within nestjs. I am coming from the .NET world where we have got something like this:
[Route("/streams/{id}")]
public IActionResult Clip(string Id) {
... more code ...
return File(myDataStream, "video/mp4", enableRangeProcessing: true);
}
Is there any analogous, similiar or comparable functionality within nestjs which I had then simply overlooked or do I really have to develop this rather cumbersome yet pretty common use-case on my own?
Kind regards
Samuel
While trying to organize the code of my first NodeJS-express project, I ran into some doubts about the use of namespaces, modules and classes. When to choose one? When another?
For example, my project is structured (simplifying) in.
routers -> controllers -> services -> repositories.
The possibilities I thought of to manage these "entities" are the following:
Classes
Classes with static methods
Singletons
Simple module export
Namespaces
Classes
I thought of avoiding them right away, since the above-mentioned entities do not need to memorize any state. Furthermore, they would complicate the code due to the need to be instantiated.
Classes with static methods
They are correct? Or rather a simple namespace or simple export of the modules?
Class + Singletons
A way of organizing the code in a "nicer" way than the simple class, but which does not convince me, since reading on the net that the singleton in TypeScript is replaceable with the namespace.
Simple module export
The way I thought to implement immediately, for example in this way (file user.repository.ts):
const add = async (user: User): Promise<void> => {
if(await canBeAdded(user)) {
//save user;
} else {
// throw error
}
}
export const UserRepository = {
add
}
It's corrects? Or am I not properly using what TypeScript offers? Being the first time I use this language, I would like to be sure I chose the right path.
Namespaces
Are they a better choice to develop the code published above? Are you advised against?
Thank you in advance for the answers! Any advice is welcome!
P.S. I know that, once the TypeScript is compiled, in Javascript the classes are practically syntactic sugar. What I'm interested in knowing are the best practices for writing good code in TypeScript.
I'm trying to use mapGetters from Vue.js but instead use NPM to install I used Vue CDN like this:
<script src="https://unpkg.com/vuex#3.0.1/dist/vuex.js"></script>
I can't do the import as usual:
import {mapGetters} from 'vuex';
And neither use mapGetters without import.
export default {
computed: mapGetters([
'doubleCounter',
'realCounter'
])}
How can I use mapGetters using Vue CDN?
export default {
computed: Vuex.mapGetters([
'doubleCounter',
'realCounter'
])
}
export default {
computed: {
...Vuex.mapGetters([
'doubleCounter',
'realCounter'
]),
otherComputedProperty () {
// implementation
}
}
}
I had run into this exact issue and this answer was perfect. The reason I replying is because in google searches you are unlikely to find this unless you include CDN in your search. With that included it is a top result as it should be. I hope others will find this in the future if they are looking for solutions when they are searching for how to use mapGetters or mapState or mapActions or mapMutations and they add the line
import { mapMutations } from 'vuex'
only to get the error in the console
Uncaught SyntaxError: Cannot use import statement outside a module
I think the answer would be fairly obvious to someone familiar with including via CND instead of via NPM, but for a relatively new cut-and-paste jockey, like myself, I was struggling to solve this problem. I didn't even think to include cdn in my google search. Only after asking in a different forum did someone suggest this post and/or including it in the search did I find this easy and clear solution.
Hopefully by posting this, the indexing will eventually include this in some of the searches I did without cdn, for the next explorer.