{"id":2881,"date":"2023-09-22T03:44:41","date_gmt":"2023-09-22T01:44:41","guid":{"rendered":"https:\/\/nguenkam.com\/blog\/?p=2881"},"modified":"2023-09-22T03:44:41","modified_gmt":"2023-09-22T01:44:41","slug":"remult-a-fullstack-typescript-crud-framework","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2023\/09\/22\/remult-a-fullstack-typescript-crud-framework\/","title":{"rendered":"Remult &#8211; A Fullstack TypeScript CRUD Framework"},"content":{"rendered":"\n<p>In the ever-evolving world of web development, having robust tools at our disposal can make a world of difference. <strong>Remult <\/strong>is one such tool, a CRUD (Create, Read, Update, Delete) framework designed specifically for Fullstack TypeScript developers. In this article, we&#8217;ll delve into the features and benefits of Remult and explore how it can streamline our development process.<\/p>\n\n\n\n<h4><strong>What is Remult?<\/strong><\/h4>\n\n\n\n<p>Remult is a powerful TypeScript framework that simplifies the creation of web applications with a focus on database operations. It provides a comprehensive set of tools and utilities to manage data and user interfaces effortlessly. With Remult, developers can efficiently build applications that interact with databases while maintaining type safety throughout the development process.<\/p>\n\n\n\n<h4><strong>Key Features of Remult<\/strong><\/h4>\n\n\n\n<ol><li><strong>Type Safety<\/strong>: TypeScript is known for its type safety, and Remult leverages this by providing strong type checking for database operations. This means we can catch potential bugs at compile time rather than runtime.<\/li><li><strong>CRUD Operations<\/strong>: Remult abstracts the complexities of database operations, making it easy to create, read, update, and delete records. It supports multiple databases, making it flexible for various project requirements.<\/li><li><strong>User Interface Components<\/strong>: Remult comes with a set of UI components that are easy to integrate into our web application. These components are designed to work seamlessly with the underlying data structure.<\/li><li><strong>Authentication and Authorization<\/strong>: Security is a top priority in web development, and Remult offers built-in authentication and authorization mechanisms to safeguard your application&#8217;s data.<\/li><li><strong>Extensibility<\/strong>: Remult is highly extensible, allowing us to customize and extend its functionality to meet the specific needs of our project.<\/li><\/ol>\n\n\n\n<h4><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">Getting Started with Remult<\/span><\/strong><\/h4>\n\n\n\n<p>To get started with Remult, we&#8217;ll need to install it using npm or yarn. Once installed, we can initialize a new Remult project and start defining our data models and user interfaces. The framework provides clear documentation and examples to guide us through the process.<\/p>\n\n\n\n<h5>Install required packages<\/h5>\n\n\n\n<p>We need\u00a0<code>Express<\/code>\u00a0to serve our app&#8217;s API, and, of course,\u00a0<code>Remult<\/code>. For development, we&#8217;ll use\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/www.npmjs.com\/package\/tsx\" target=\"_blank\">tsx<\/a>\u00a0to run the API server<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm i express remult\r\nnpm i --save-dev @types\/express tsx<\/code><\/pre>\n\n\n\n<h5>Create the API server project<\/h5>\n\n\n\n<p>The starter API server TypeScript project contains a single module that initializes\u00a0<code>Express<\/code>, and begins listening for API requests.<\/p>\n\n\n\n<p>Let&#8217;s open our IDE and  add the following entry to the\u00a0<code>compilerOptions<\/code>\u00a0section of the\u00a0<code>tsconfig.json<\/code>\u00a0file to enable the use of Synthetic Default Imports and ES Module Interop in the app.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ tsconfig.json\r\n\r\n{\r\n...\r\n  \"compilerOptions\": {\r\n    ...\r\n    \"allowSyntheticDefaultImports\": true,\r\n    \"esModuleInterop\": true,\r\n   ...\r\n  }\r\n...\r\n}<\/code><\/pre>\n\n\n\n<ul start=\"2\"><li>Let&#8217; s create a\u00a0<code>server<\/code>\u00a0folder under the\u00a0<code>src\/<\/code>\u00a0folder created by Angular cli.<\/li><li>let&#8217;s create an\u00a0<code>index.ts<\/code>\u00a0file in the\u00a0<code>src\/server\/<\/code>\u00a0folder with the following code:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ src\/server\/index.ts\r\n\r\nimport express from \"express\"\r\n\r\nconst app = express()\r\n\r\napp.listen(3002, () => console.log(\"Server started\"))<\/code><\/pre>\n\n\n\n<h5>Bootstrap Remult in the back-end<\/h5>\n\n\n\n<p>Remult is loaded in the back-end as an&nbsp;<code>Express middleware<\/code>.<\/p>\n\n\n\n<ul><li>Create an\u00a0<code>api.ts<\/code>\u00a0file in the\u00a0<code>src\/server\/<\/code>\u00a0folder with the following code:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ src\/server\/api.ts\r\n\r\nimport { remultExpress } from \"remult\/remult-express\"\r\n\r\nexport const api = remultExpress()<\/code><\/pre>\n\n\n\n<ul><li>Add the highlighted code lines to register the middleware in the main server module\u00a0<code>index.ts<\/code>.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ src\/server\/index.ts\r\n\r\nimport express from \"express\"\r\nimport { api } from \".\/api\"\r\n\r\nconst app = express()\r\napp.use(api)\r\n\r\napp.listen(3002, () => console.log(\"Server started\"))<\/code><\/pre>\n\n\n\n<h5>Proxy API requests from Angular DevServer to the API server<\/h5>\n\n\n\n<p>the API server will be listening on\u00a0<code>http:\/\/localhost:3002<\/code>, while the Angular dev server is served from the default\u00a0<code>http:\/\/localhost:4200<\/code>.<\/p>\n\n\n\n<p>We&#8217;ll use the\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/angular.io\/guide\/build#proxying-to-a-backend-server\" target=\"_blank\">proxy<\/a>\u00a0feature of Angular dev server to divert all calls for\u00a0<code>http:\/\/localhost:4200\/api<\/code>\u00a0to our dev API server.<\/p>\n\n\n\n<p>Let&#8217;s create a file\u00a0<code>proxy.conf.json<\/code>\u00a0in the root folder, with the following contents:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ proxy.conf.json\r\n\r\n{\r\n  \"\/api\": {\r\n    \"target\": \"http:\/\/localhost:3002\",\r\n    \"secure\": false\r\n  }\r\n}<\/code><\/pre>\n\n\n\n<h5>Run the app<\/h5>\n\n\n\n<p>Let us add 2 scripts : the first called\u00a0<code><strong>dev<\/strong><\/code>\u00a0that will run the angular\u00a0<code>dev<\/code>\u00a0server with the proxy configuration we&#8217;ve set<\/p>\n\n\n\n<p> and a second script called\u00a0<code><strong>dev-node<\/strong><\/code>\u00a0to run the api.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ package.json\r\n\r\n\"dev\": \"ng serve --proxy-config proxy.conf.json --open\",\r\n\"dev-node\": \"tsx watch src\/server\",<\/code><\/pre>\n\n\n\n<p>Open a terminal and start the angular dev server.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm run dev<\/code><\/pre>\n\n\n\n<p>Let&#8217;s open another terminal and start the\u00a0<code>node<\/code>\u00a0server<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm run dev-node<\/code><\/pre>\n\n\n\n<p>The server is now running and listening on port 3002.&nbsp;<code>tsx<\/code>&nbsp;is watching for file changes and will restart the server when code changes are saved.<\/p>\n\n\n\n<p>The default Angular app main screen should be displayed on the regular port &#8211; 4200. Open it in the browser at\u00a0<a rel=\"noreferrer noopener\" href=\"http:\/\/localhost:4200\/\" target=\"_blank\">http:\/\/localhost:4200\/<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4><strong>Conclusion<\/strong><\/h4>\n\n\n\n<p>Remult is a game-changer for Fullstack TypeScript developers. It combines the power of TypeScript with a robust set of tools for database interaction, making it easier than ever to build scalable and secure web applications.<\/p>\n\n\n\n<p>It offers us a type-safe, efficient, and extensible solution for CRUD operations in Fullstack TypeScript applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the ever-evolving world of web development, having robust tools at our disposal can make a world of difference. Remult is one such tool, a CRUD (Create, Read, Update, Delete) framework designed specifically for Fullstack TypeScript developers. In this article, we&#8217;ll delve into the features and benefits of Remult and explore how it can streamline [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2882,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[37,83],"tags":[446,286,729,368,205,728,730],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2881"}],"collection":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=2881"}],"version-history":[{"count":1,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2881\/revisions"}],"predecessor-version":[{"id":2883,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2881\/revisions\/2883"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/2882"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=2881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=2881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=2881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}