Skip to main content

Posts

Showing posts with the label Node.js

NestJS File Upload

In this article, we are going to understand the steps to create a file uploading endpoint in the NestJS application. Key Features In NestJS File Upload: Let us know some key features of NestJS file upload before implementing a sample application. FileInterceptor: The 'FileInterceptor' will be decorated on top of the file upload endpoint. This interceptor will read single file data from the form posted to the endpoint. export declare function FilesInterceptor(fieldName: string, localOptions?: MulterOptions): Type<NestInterceptor>; Here we can observe the 'fieldName' first input parameter this value should be a match with our 'name' attribute value on the form file input field. So our interceptor read our files that are attached to the file input field. Another input parameter of 'MulterOptions' that provides configuration like file destination path, customizing file name, etc. FilesInterceptor: The 'FilesInterceptor' will be decorated on t

NestJS API Integration With GraphQL Using Code First Approach

What Is GraphQL?: GraphQL is a query language for your API and a server-side runtime for executing queries by using a schema type system you defined for your data. GraphQL is not tied to any specific programming language(like NestJS, Java, .NET, etc) or database or storage engine. How GraphQL Different From Rest API: GraphQL exposes a single endpoint. Http-Post is the only Http verb recommended by supported by GraphQL API. Client applications(consumers of GraphQL API) can give instructions to GraphQL API about the response data. Code First vs Schema Approach: Code First Approach: In Code First Approach we use Typescript class to which need to apply GraphQL decorator on top of classes and also on top of properties inside of the class. These decorators help to auto-generate the raw GraphQL Schema. So in Code First Approach we no need to learn or concentrate to write the GraphQL Schema. Schema First Approach: GraphQL SDL(schema definition language) is a new syntactic query type language,

NestJS API Integration With GraphQL Using Schema First Approach

What Is GraphQL?: GraphQL is a query language for your API and a server-side runtime for executing queries by using a schema type system you defined for your data. Graphql is not tied to any specific programming language(like NestJS, Java, .NET, etc) or database or storage engine. How GraphQL Different From Rest API: GraphQL exposes a single endpoint. HTTP-POST is the only Http verb recommended by GraphQL. Client applications(consumers of GraphQL API) can give instructions to GraphQL API about the response data. Schema vs Code First Approach: Schema First Approach - GraphQL SDL (Schema definition language) is a new syntax language, which is independent of any programming language and also integrates with any programming language. But while integrating with any programming language GraphQL Schema needs to be mapped with objects or classes or interface of the specific programming language to build communication between GraphQL Schema and programming language. In Nest

NestJS API CRUD Operations With MongoDB

Introduction: NestJS is a framework used to develop server-side applications. NestJS built on top of Node.js frameworks like Express. It is a combination of Progressive Javascript, Object-Oriented Programming, Functional Programming, and Functional Reactive Programming. Nest CLI Installation: Using Nest CLI we are able to generate the NestJS starter project with the default template. To install Nest CLI globally over our system open command prompt and run the command               npm i -g @nestjs/cli Now create a sample project by using Nest CLI command              nest new your_project_name package.json: Now open the package.json file from the sample application created, you can observe few properties like "scripts", "dependencies", and "devDependencies". "dependencies" contains all plugins to be installed and used them to run the application. "devDependencies" contain all plugins to be installed and used them