{"id":300,"date":"2022-07-03T22:05:58","date_gmt":"2023-08-04T08:49:36","guid":{"rendered":"https:\/\/www.silicloud.com\/ja\/blog\/index.php\/2023\/11\/30\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/"},"modified":"2025-07-31T22:27:54","modified_gmt":"2025-07-31T13:27:54","slug":"nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/","title":{"rendered":"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u8457\u8005\u306f\u3001Write for Donations\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4e00\u74b0\u3068\u3057\u3066\u3001\u5bc4\u4ed8\u306e\u53d7\u9818\u5148\u3068\u3057\u3066Tech Education Fund\u3092\u9078\u629e\u3057\u307e\u3057\u305f\u3002<\/p>\n<h3>\u4ee5\u4e0b\u306e\u6587\u7ae0\u3092\u65e5\u672c\u8a9e\u3067\u81ea\u7136\u306a\u8a00\u3044\u65b9\u3067\u8a00\u3044\u63db\u3048\u308b\uff081\u3064\u306e\u9078\u629e\u80a2\u306e\u307f\uff09\uff1a<br \/>\n\u30a4\u30f3\u30c8\u30ed\u30c0\u30af\u30b7\u30e7\u30f3<\/h3>\n<p>URL\u3068\u306f\u3001Uniform Resource Locator\u306e\u7565\u79f0\u3067\u3001\u30a6\u30a7\u30d6\u4e0a\u306e\u56fa\u6709\u30ea\u30bd\u30fc\u30b9\u306b\u5272\u308a\u5f53\u3066\u3089\u308c\u308b\u30a2\u30c9\u30ec\u30b9\u3067\u3059\u3002URL\u306f\u4e00\u610f\u3067\u3042\u308b\u305f\u3081\u3001\u540c\u3058URL\u3092\u6301\u30642\u3064\u306e\u30ea\u30bd\u30fc\u30b9\u306f\u5b58\u5728\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>URL\u306e\u9577\u3055\u3068\u8907\u96d1\u3055\u306f\u3055\u307e\u3056\u307e\u3067\u3059\u3002URL\u306fexample.com\u306e\u3088\u3046\u306b\u77ed\u304f\u3001\u307e\u305fhttp:\/\/llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk\u306e\u3088\u3046\u306b\u9577\u304f\u306a\u308b\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002\u8907\u96d1\u306aURL\u306f\u898b\u305f\u76ee\u304c\u60aa\u304f\u3001\u691c\u7d22\u30a8\u30f3\u30b8\u30f3\u6700\u9069\u5316\uff08SEO\uff09\u306e\u554f\u984c\u3092\u5f15\u304d\u8d77\u3053\u3057\u3001\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u8a08\u753b\u306b\u60aa\u5f71\u97ff\u3092\u53ca\u307c\u3059\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002URL\u77ed\u7e2e\u30b5\u30fc\u30d3\u30b9\u306f\u3001\u9577\u3044URL\u3092\u77ed\u304f\u5909\u63db\u3057\u3001\u77ed\u3044URL\u304c\u4f7f\u7528\u3055\u308c\u305f\u969b\u306b\u30e6\u30fc\u30b6\u30fc\u3092\u5143\u306eURL\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u3001NestJS\u3092\u4f7f\u7528\u3057\u3066URL\u77ed\u7e2e\u30b5\u30fc\u30d3\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u307e\u305a\u3001URL\u306e\u77ed\u7e2e\u3068\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306e\u30ed\u30b8\u30c3\u30af\u3092\u30b5\u30fc\u30d3\u30b9\u306b\u5b9f\u88c5\u3057\u307e\u3059\u3002\u6b21\u306b\u3001\u77ed\u7e2e\u3068\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u5bb9\u6613\u306b\u3059\u308b\u305f\u3081\u306e\u30eb\u30fc\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<h2>\u524d\u63d0\u6761\u4ef6<\/h2>\n<p>\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306b\u5f93\u3046\u305f\u3081\u306b\u306f\u3001\u4ee5\u4e0b\u304c\u5fc5\u8981\u3067\u3059\uff1a<\/p>\n<ul class=\"post-ul\">\n<li>A local development environment for Node.js version 16 or higher. Follow the How To Install Node.js and Create a Local Development Environment tutorial that suits your system.<\/li>\n<li>The NestJS CLI installed on your system, which you will set up in Step 1, and familiarity with NestJS. Review Getting Started with NestJS.<\/li>\n<li>Familiarity with TypeScript. You can review the How To Code in TypeScript series to learn more.<\/li>\n<\/ul>\n<h2>\u30b9\u30c6\u30c3\u30d71\uff1a\u958b\u767a\u74b0\u5883\u306e\u6e96\u5099<\/h2>\n<p>\u3053\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u306f\u3001URL\u306e\u77ed\u7e2e\u30ed\u30b8\u30c3\u30af\u3092\u5b9f\u88c5\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u306a\u3059\u3079\u3066\u306e\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002\u307e\u305a\u3001NestJS\u3092\u30b0\u30ed\u30fc\u30d0\u30eb\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3001\u65b0\u3057\u3044NestJS\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30dc\u30a4\u30e9\u30fc\u30d7\u30ec\u30fc\u30c8\u3092\u751f\u6210\u3057\u3001\u4f9d\u5b58\u95a2\u4fc2\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3001\u30b5\u30fc\u30d3\u30b9\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u6700\u521d\u306b\u3001 \u4ee5\u524d\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u3001Nest CLI \u3092\u30b0\u30ed\u30fc\u30d0\u30eb\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002\u3053\u306eCLI\u3092\u4f7f\u7528\u3057\u3066\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3068\u5fc5\u8981\u306a\u30d5\u30a1\u30a4\u30eb\u3092\u751f\u6210\u3057\u307e\u3059\u3002Nest CLI \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u306b\u306f\u3001\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-g<\/span> @nestjs\/cli<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>-g\u30d5\u30e9\u30b0\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30b7\u30b9\u30c6\u30e0\u5168\u4f53\u306bNest CLI\u304c\u30b0\u30ed\u30fc\u30d0\u30eb\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u51fa\u529b\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002 (Ika no shutsuryoku ga hy\u014dji sa remasu.)<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\">\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<p><span class=\"token punctuation\">..<\/span>.<\/li>\n<li data-prefix=\"$\">added <span class=\"token number\">249<\/span> packages, and audited <span class=\"token number\">250<\/span> packages <span class=\"token keyword\">in<\/span> 3m<\/li>\n<li data-prefix=\"$\"><span class=\"token number\">39<\/span> packages are looking <span class=\"token keyword\">for<\/span> funding<\/li>\n<li data-prefix=\"$\">run <span class=\"token function\">npm<\/span> fund <span class=\"token keyword\">for<\/span> details<\/li>\n<li data-prefix=\"$\">found <span class=\"token number\">0<\/span> vulnerabilities<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u305d\u306e\u5f8c\u3001\u65b0\u3057\u3044\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3001\u5fc5\u8981\u306a\u30dc\u30a4\u30e9\u30fc\u30d7\u30ec\u30fc\u30c8\u306e\u30b9\u30bf\u30fc\u30bf\u30fc\u30d5\u30a1\u30a4\u30eb\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\">nest new URL-shortener<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u4ee5\u4e0b\u306e\u51fa\u529b\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\">\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<p><span class=\"token punctuation\">..<\/span>.<\/li>\n<li data-prefix=\"$\">\u26a1 We will scaffold your app <span class=\"token keyword\">in<\/span> a few seconds<span class=\"token punctuation\">..<\/span><\/li>\n<li data-prefix=\"$\"><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/.eslintrc.js <span class=\"token punctuation\">(<\/span><span class=\"token number\">631<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/.prettierrc <span class=\"token punctuation\">(<\/span><span class=\"token number\">51<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/nest-cli.json <span class=\"token punctuation\">(<\/span><span class=\"token number\">118<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/package.json <span class=\"token punctuation\">(<\/span><span class=\"token number\">2002<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/README.md <span class=\"token punctuation\">(<\/span><span class=\"token number\">3339<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/tsconfig.build.json <span class=\"token punctuation\">(<\/span><span class=\"token number\">97<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/tsconfig.json <span class=\"token punctuation\">(<\/span><span class=\"token number\">546<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/src\/app.controller.spec.ts <span class=\"token punctuation\">(<\/span><span class=\"token number\">617<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/src\/app.controller.ts <span class=\"token punctuation\">(<\/span><span class=\"token number\">274<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/src\/app.module.ts <span class=\"token punctuation\">(<\/span><span class=\"token number\">249<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/src\/app.service.ts <span class=\"token punctuation\">(<\/span><span class=\"token number\">142<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/src\/main.ts <span class=\"token punctuation\">(<\/span><span class=\"token number\">208<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/test\/app.e2e-spec.ts <span class=\"token punctuation\">(<\/span><span class=\"token number\">630<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\">CREATE url-shortener\/test\/jest-e2e.json <span class=\"token punctuation\">(<\/span><span class=\"token number\">183<\/span> bytes<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\"><\/li>\n<li data-prefix=\"$\">? Which package manager would you \u2764\ufe0f to use? <span class=\"token punctuation\">(<\/span>Use arrow keys<span class=\"token punctuation\">)<\/span><\/li>\n<li data-prefix=\"$\"><span class=\"token operator\">&gt;<\/span> <span class=\"token function\">npm<\/span><\/li>\n<li data-prefix=\"$\"><span class=\"token function\">yarn<\/span><\/li>\n<li data-prefix=\"$\"><span class=\"token function\">pnpm<\/span><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>npm\u3092\u9078\u3093\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u51fa\u529b\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\">\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<p>\u221a Installation <span class=\"token keyword\">in<\/span> progress<span class=\"token punctuation\">..<\/span>. \u2615<\/li>\n<li data-prefix=\"$\"><\/li>\n<li data-prefix=\"$\">\ud83d\ude80 Successfully created project url-shortener<\/li>\n<li data-prefix=\"$\">\ud83d\udc49 Get started with the following commands:<\/li>\n<li data-prefix=\"$\"><\/li>\n<li data-prefix=\"$\">$ <span class=\"token builtin class-name\">cd<\/span> url-shortener<\/li>\n<li data-prefix=\"$\">$ <span class=\"token function\">npm<\/span> run start<\/li>\n<li data-prefix=\"$\"><\/li>\n<li data-prefix=\"$\">Thanks <span class=\"token keyword\">for<\/span> installing Nest \ud83d\ude4f<\/li>\n<li data-prefix=\"$\">Please consider donating to our <span class=\"token function\">open<\/span> collective<\/li>\n<li data-prefix=\"$\">to <span class=\"token builtin class-name\">help<\/span> us maintain this package.<\/li>\n<li data-prefix=\"$\"><\/li>\n<li data-prefix=\"$\">\ud83c\udf77 Donate: https:\/\/opencollective.com\/nest<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u4f5c\u6210\u3057\u305f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token builtin class-name\">cd<\/span> url-shortener<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u3053\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u4ee5\u964d\u306e\u3059\u3079\u3066\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<div class=\"post-conf-note\">\n<p class=\"post-conf-desc\">Note<\/p>\n<div>\u6ce8\u610f\uff1aNestJS CLI\u306f\u65b0\u3057\u3044\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3059\u308b\u969b\u306b\u3001app.controller.ts\u3001app.controller.spec.ts\u3001app.service.ts\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u3053\u308c\u3089\u306f\u5fc5\u8981\u3042\u308a\u307e\u305b\u3093\u306e\u3067\u3001\u524a\u9664\u3059\u308b\u304b\u7121\u8996\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/div>\n<\/div>\n<p>\u6b21\u306b\u3001\u5fc5\u8981\u306a\u4f9d\u5b58\u95a2\u4fc2\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u3001NodeJS\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u3067\u3042\u308bnpm\u3092\u4f7f\u7528\u3057\u3066\u3001\u3044\u304f\u3064\u304b\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u5fc5\u8981\u306a\u4f9d\u5b58\u95a2\u4fc2\u306b\u306f\u3001TypeORM\u3001SQLite\u3001Class-validator\u3001Class-transformer\u3001\u304a\u3088\u3073Nano-ID\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>TypeORM\u306f\u3001TypeScript\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u30ea\u30ec\u30fc\u30b7\u30e7\u30ca\u30eb\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u76f8\u4e92\u4f5c\u7528\u3092\u5bb9\u6613\u306b\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30ea\u30ec\u30fc\u30b7\u30e7\u30ca\u30eb\u30de\u30c3\u30d1\u30fc\u3067\u3059\u3002NestJS\u72ec\u81ea\u306e@nestjs\/typeorm\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u3088\u308a\u3001\u3053\u306eORM\u306fNestJS\u3068\u30b7\u30fc\u30e0\u30ec\u30b9\u306b\u9023\u643a\u3057\u307e\u3059\u3002NestJS\u306e\u30cd\u30a4\u30c6\u30a3\u30d6typeorm\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u3053\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u4f7f\u7528\u3057\u3066\u3001SQLite\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u306e\u3084\u308a\u53d6\u308a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p>TypeORM\u3068\u305d\u306e\u5c02\u7528\u306eNestJS\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u305f\u3081\u306b\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> @nestjs\/typeorm typeorm<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>SQLite\u306f\u3001\u5c0f\u3055\u304f\u3066\u9ad8\u901f\u3067\u81ea\u5df1\u5b8c\u7d50\u578b\u306eSQL\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30a8\u30f3\u30b8\u30f3\u3092\u5b9f\u88c5\u3057\u305f\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u3053\u306e\u4f9d\u5b58\u6027\u3092\u4f7f\u7528\u3057\u3066\u3001\u77ed\u7e2eURL\u3092\u4fdd\u5b58\u3057\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3057\u3066\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3001SQLite\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> sqlite3<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>class-validator\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001NestJS\u3067\u30c7\u30fc\u30bf\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306b\u4f7f\u7528\u3055\u308c\u308b\u30c7\u30b3\u30ec\u30fc\u30bf\u3092\u542b\u3093\u3067\u3044\u307e\u3059\u3002\u3053\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u3001\u30c7\u30fc\u30bf\u30c8\u30e9\u30f3\u30b9\u30d5\u30a1\u30fc\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u5171\u306b\u4f7f\u7528\u3057\u3066\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u9001\u4fe1\u3055\u308c\u308b\u30c7\u30fc\u30bf\u3092\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3057\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3001class-validator\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> class-validator<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>class-transformer\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001\u30d7\u30ec\u30fc\u30f3\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u5909\u63db\u3057\u305f\u308a\u3001\u305d\u306e\u9006\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u4f9d\u5b58\u95a2\u4fc2\u306f\u3001\u5358\u72ec\u3067\u306f\u52d5\u4f5c\u3057\u306a\u3044\u305f\u3081\u3001class-validator\u3068\u4e00\u7dd2\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3001class-transformer\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> class-transformer<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Nano-ID\u306f\u30bb\u30ad\u30e5\u30a2\u3067URL\u306b\u9069\u3057\u305f\u30e6\u30cb\u30fc\u30af\u306a\u6587\u5b57\u5217ID\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\u3067\u3059\u3002URL\u306e\u30ea\u30bd\u30fc\u30b9\u3054\u3068\u306b\u30e6\u30cb\u30fc\u30af\u306aID\u3092\u751f\u6210\u3059\u308b\u305f\u3081\u306b\u3001\u3053\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u30ca\u30ce-ID\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u305f\u3081\u306b\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> nanoid@^3.0.0<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"post-conf-note\">\n<p class=\"post-conf-desc\">Note<\/p>\n<div>\u6ce8\u610f\uff1a3.0.0\u3088\u308a\u3082\u9ad8\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u306eNano-ID\u306f\u3001CommonJS\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30b5\u30dd\u30fc\u30c8\u304c\u7121\u52b9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u554f\u984c\u306f\u3001TypeScript\u30b3\u30f3\u30d1\u30a4\u30e9\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u305fJavaScript\u30b3\u30fc\u30c9\u304c\u307e\u3060CommonJS\u30e2\u30b8\u30e5\u30fc\u30eb\u30b7\u30b9\u30c6\u30e0\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/div>\n<\/div>\n<p>\u5fc5\u8981\u306a\u4f9d\u5b58\u95a2\u4fc2\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u5f8c\u3001Nest CLI\u3092\u4f7f\u7528\u3057\u3066\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3001\u30b5\u30fc\u30d3\u30b9\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u751f\u6210\u3057\u307e\u3059\u3002\u30e2\u30b8\u30e5\u30fc\u30eb\u306f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u6574\u7406\u3057\u3001\u30b5\u30fc\u30d3\u30b9\u306fURL\u77ed\u7e2e\u306e\u5168\u3066\u306e\u30ed\u30b8\u30c3\u30af\u3092\u53d6\u308a\u6271\u3044\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306f\u30eb\u30fc\u30c8\u3092\u53d6\u308a\u6271\u3044\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u751f\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\">nest generate module url<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u4ee5\u4e0b\u306e\u51fa\u529b\u7d50\u679c\u304c\u8868\u793a\u3055\u308c\u307e\u3059\uff1a<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>CREATE src\/url\/url.module.ts (80 bytes) UPDATE src\/app.module.ts (304 bytes)<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u6b21\u306b\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3001\u30b5\u30fc\u30d3\u30b9\u3092\u751f\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\">nest generate <span class=\"token function\">service<\/span> url &#8211;no-spec<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&#8211;no-spec\u30d5\u30e9\u30b0\u306fNest CLI\u306b\u5bfe\u3057\u3066\u3001\u30c6\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u751f\u6210\u305b\u305a\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u751f\u6210\u3059\u308b\u3088\u3046\u6307\u793a\u3057\u307e\u3059\u3002\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u30c6\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306f\u5fc5\u8981\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u51fa\u529b\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>CREATE src\/url\/url.service.ts (87 bytes) UPDATE src\/url\/url.module.ts (151 bytes)<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u305d\u306e\u5f8c\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u751f\u6210\u3059\u308b\u305f\u3081\u306b\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\">nest generate controller url &#8211;no-spec<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u4ee5\u4e0b\u306e\u51fa\u529b\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>CREATE src\/url\/url.controller.ts (95 bytes) UPDATE src\/url\/url.module.ts (233 bytes)<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u3053\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u306f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u958b\u767a\u306b\u5fc5\u8981\u306a\u307b\u3068\u3093\u3069\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002\u6b21\u306b\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30b9\u30c6\u30c3\u30d72- \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u63a5\u7d9a\u3059\u308b<\/h2>\n<p>\u3053\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u5185\u306eURL\u30ea\u30bd\u30fc\u30b9\u3092\u30e2\u30c7\u30eb\u5316\u3059\u308b\u305f\u3081\u306b\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306f\u3001\u4fdd\u5b58\u3055\u308c\u305f\u30c7\u30fc\u30bf\u306e\u5fc5\u8981\u306a\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u542b\u3080\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002\u307e\u305f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u9593\u306e\u30a2\u30af\u30bb\u30b9\u30ec\u30a4\u30e4\u30fc\u3068\u306a\u308b\u30ea\u30dd\u30b8\u30c8\u30ea\u3082\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u597d\u304d\u306a\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\uff08\u305f\u3068\u3048\u3070nano\uff09\u3092\u4f7f\u3063\u3066\u3001src\/url\u30d5\u30a9\u30eb\u30c0\u5185\u306burl.entity.ts\u3068\u3044\u3046\u540d\u524d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3001\u958b\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">nano<\/span> src\/url\/url.entity.ts<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u306f\u3001\u30c7\u30fc\u30bf\u3092\u30e2\u30c7\u30eb\u5316\u3059\u308b\u305f\u3081\u306e\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001src\/url\/url.entity.ts\u30d5\u30a1\u30a4\u30eb\u306b\u6b21\u306eTypeScript\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\u4ee5\u4e0b\u306f\u3001src\/url\/url.entity.ts\u306e\u8868\u73fe\u3092\u65e5\u672c\u8a9e\u3067\u81ea\u7136\u306b\u8a00\u3044\u63db\u3048\u308b\u3082\u306e\u3067\u3059\uff081\u3064\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u307f\uff09\uff1a<br \/>\n\u30a8\u30b9\u30a2\u30fc\u30eb\u30b7\u30fc\/\u30e6\u30fc\u30a2\u30fc\u30eb\u30b7\u30fc\/\u30e6\u30fc\u30a2\u30fc\u30eb.\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3.ts<\/div>\n<pre class=\"post-pre\"><code>import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';\r\n\r\n@Entity()\r\nexport class Url {\r\n    @PrimaryGeneratedColumn()\r\n    id: number;\r\n\r\n    @Column()\r\n    urlCode: string;\r\n\r\n    @Column()\r\n    longUrl: string;\r\n\r\n    @Column()\r\n    shortUrl: string;\r\n}\r\n<\/code><\/pre>\n<p>\u6700\u521d\u306b\u3001&#8217;typeorm&#8217;\u304b\u3089\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3001\u30ab\u30e9\u30e0\u3001\u304a\u3088\u3073PrimaryGeneratedColumn\u306e\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u30b3\u30fc\u30c9\u306f\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3068\u3057\u3066\u30af\u30e9\u30b9\u3092\u30de\u30fc\u30af\u3059\u308bEntity\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u3067\u6ce8\u91c8\u4ed8\u3051\u3055\u308c\u305f\u30af\u30e9\u30b9Url\u3092\u4f5c\u6210\u3057\u3066\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u5404\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u9069\u5207\u306a\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u3067\u6307\u5b9a\u304a\u3088\u3073\u6ce8\u91c8\u4ed8\u3051\u3055\u308c\u307e\u3059\uff1aid\u306b\u306fPrimaryGeneratedColumn\u304c\u4f7f\u7528\u3055\u308c\u3001\u305d\u306e\u4ed6\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u306fColumn\u304c\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002PrimaryGeneratedColumn\u306f\u3001\u6ce8\u91c8\u3092\u4ed8\u3051\u305f\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u81ea\u52d5\u7684\u306b\u5024\u3092\u751f\u6210\u3059\u308b\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u3067\u3059\u3002 TypeOrm\u306f\u5404\u30ea\u30bd\u30fc\u30b9\u306b\u5bfe\u3057\u3066id\u3092\u751f\u6210\u3059\u308b\u305f\u3081\u306b\u3053\u308c\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002Column\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u5185\u306e\u5217\u3068\u3057\u3066\u6ce8\u91c8\u3092\u4ed8\u3051\u305f\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8ffd\u52a0\u3059\u308b\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u3067\u3059\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u4fdd\u5b58\u3059\u3079\u304d\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002 (D\u0113tab\u0113su ni hozon subeki puropat\u012b wa ika no t\u014dri desu.)<\/p>\n<ul class=\"post-ul\">\n<li>id is the primary key for the database table.<\/li>\n<li>urlCode is the unique id generated by the nanoid package and will be used to identify each URL.<\/li>\n<li>longUrl is the URL sent to your application to be shortened.<\/li>\n<li>shortUrl is the shortened URL.<\/li>\n<\/ul>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u3066\u9589\u3058\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u6b21\u306b\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u9593\u306b\u63a5\u7d9a\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u6700\u521d\u306b\u3001nano\u307e\u305f\u306f\u304a\u597d\u307f\u306e\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u3067src\/app.module.ts\u3092\u958b\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">nano<\/span> src\/app.module.ts<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u305d\u306e\u5f8c\u3001\u30d5\u30a1\u30a4\u30eb\u306b\u30cf\u30a4\u30e9\u30a4\u30c8\u3055\u308c\u305f\u884c\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>src\/app.module.ts\u3092\u65e5\u672c\u8a9e\u3067\u8a00\u3044\u63db\u3048\u308b\u3068\u3001\u300csrc\/app.module.ts\u30d5\u30a1\u30a4\u30eb\u300d\u3067\u3059\u3002<\/div>\n<pre class=\"post-pre\"><code>import { Module } from '@nestjs\/common';\r\n<mark>import { TypeOrmModule } from '@nestjs\/typeorm';<\/mark>\r\n<mark>import { Url } from '.\/url\/url.entity';<\/mark>\r\nimport { UrlModule } from '.\/url\/url.module';\r\n\r\n@Module({\r\n  imports: [\r\n    <mark>TypeOrmModule.forRoot({<\/mark>\r\n      <mark>type: 'sqlite',<\/mark>\r\n      <mark>database: 'URL.sqlite',<\/mark>\r\n      <mark>entities: [Url],<\/mark>\r\n      <mark>synchronize: true,<\/mark>\r\n    <mark>}),<\/mark>\r\n    UrlModule<mark>,<\/mark>\r\n  ],\r\n  controllers: [],\r\n  providers: [],\r\n})\r\nexport class AppModule {}\r\n<\/code><\/pre>\n<p>\u6700\u521d\u306b\u3001@nestjs\/typeorm\u304b\u3089TypeOrmModule\u3068\u3001.\/url\/url.entity\u304b\u3089Url\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002AppController\u3068AppService\u306b\u95a2\u9023\u3059\u308b\u884c\u304c\u307e\u3060\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u30d5\u30a1\u30a4\u30eb\u5185\u306b\u6b8b\u3057\u3066\u304a\u3044\u3066\u3082\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u6b8b\u308a\u306b\u5f71\u97ff\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u30a4\u30f3\u30dd\u30fc\u30c8\u914d\u5217\u5185\u3067\u3001TypeOrmModule\u306eforRoot\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5185\u306e\u3059\u3079\u3066\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u901a\u3058\u3066\u63a5\u7d9a\u3092\u5171\u6709\u3057\u307e\u3059\u3002forRoot\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u8a2d\u5b9a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5f15\u6570\u3068\u3057\u3066\u53d7\u3051\u53d6\u308a\u307e\u3059\u3002<\/p>\n<p>\u69cb\u6210\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u306f\u3001\u63a5\u7d9a\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3089\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul class=\"post-ul\">\n<li>The type property denotes the kind of database you are using TypeOrm to interact with. In this case, it is set to &#8216;sqlite&#8217;.<\/li>\n<li>The database property denotes the preferred name for your database. In this case, it is set to &#8216;URL.sqlite&#8217;.<\/li>\n<li>The entities property is an array of all the entities in your project. In this case, you have just one entity specified as Url inside the array.<\/li>\n<li>The synchronize option automatically syncs your database tables with your entity and updates the tables each time you run the code. In this case, it is set to true.<\/li>\n<\/ul>\n<div class=\"post-conf-note\">\n<p class=\"post-conf-desc\">Note<\/p>\n<div>\u6ce8\u610f\uff1a\u958b\u767a\u74b0\u5883\u3067\u306f\u3001synchronize\u3092true\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u7406\u60f3\u7684\u3067\u3059\u3002\u3057\u304b\u3057\u3001\u672c\u756a\u74b0\u5883\u3067\u306f\u5e38\u306bfalse\u306b\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u306a\u305c\u306a\u3089\u3001\u30c7\u30fc\u30bf\u306e\u640d\u5931\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3067\u3059\u3002<\/div>\n<\/div>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u3066\u9589\u3058\u308b\u3002<\/p>\n<p>\u6b21\u306b\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u9593\u306b\u30a2\u30af\u30bb\u30b9\u30ec\u30a4\u30e4\u30fc\u3068\u3057\u3066\u6a5f\u80fd\u3059\u308b\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u89aa\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u63a5\u7d9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u63a5\u7d9a\u306b\u3088\u308a\u3001Nest\u3068TypeOrm\u306f\u81ea\u52d5\u7684\u306b\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>src\/url\/url.module.ts\u3092\u958b\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">nano<\/span> src\/url\/url.module.ts<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u65e2\u5b58\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u3001\u30cf\u30a4\u30e9\u30a4\u30c8\u3055\u308c\u305f\u884c\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\n<p>src\/url\/url.module.ts\u306e\u5185\u5bb9\u3092\u65e5\u672c\u8a9e\u3067\u8a00\u3044\u63db\u3048\u308b\u3068\u3001\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\uff1a<\/p>\n<p>\u300csrc\/url\/url.module.ts\u300d\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u30d5\u30a1\u30a4\u30eb\u3002<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>import { Module } from '@nestjs\/common';\r\nimport { UrlService } from '.\/url.service';\r\nimport { UrlController } from '.\/url.controller';\r\n<mark>import { TypeOrmModule } from '@nestjs\/typeorm';<\/mark>\r\n<mark>import { Url } from '.\/url.entity';<\/mark>\r\n\r\n@Module({\r\n  <mark>imports: [TypeOrmModule.forFeature([Url])],<\/mark>\r\n  providers: [UrlService],\r\n  controllers: [UrlController],\r\n})\r\nexport class UrlModule {}\r\n<\/code><\/pre>\n<p>@Module\u30c7\u30b3\u30ec\u30fc\u30bf\u306e\u5185\u90e8\u3067\u3001@nestjs\/typeorm\u304b\u3089TypeOrmModule\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3001.\/url.entity\u304b\u3089Url\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3066\u3001imports\u914d\u5217\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002imports\u914d\u5217\u306e\u5185\u90e8\u3067\u3001TypeOrmModule\u306eforFeature\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002forFeature\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306e\u914d\u5217\u3092\u5f15\u6570\u3068\u3057\u3066\u53d7\u3051\u53d6\u308b\u305f\u3081\u3001Url\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u6e21\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u3066\u9589\u3058\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>Nest\u3068TypeOrm\u306f\u3001\u30b5\u30fc\u30d3\u30b9\u3068\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u9593\u306e\u30a2\u30af\u30bb\u30b9\u30ec\u30a4\u30e4\u30fc\u3068\u3057\u3066\u6a5f\u80fd\u3059\u308b\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u88cf\u3067\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u306f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3057\u307e\u3057\u305f\u3002URL\u306e\u77ed\u7e2e\u30ed\u30b8\u30c3\u30af\u306e\u5b9f\u88c5\u306b\u9032\u3080\u6e96\u5099\u304c\u6574\u3044\u307e\u3057\u305f\u3002<\/p>\n<h2>\u30b9\u30c6\u30c3\u30d73 \u2014 \u30b5\u30fc\u30d3\u30b9\u30ed\u30b8\u30c3\u30af\u306e\u5b9f\u88c5<\/h2>\n<p>\u3053\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u306f\u30012\u3064\u306e\u30e1\u30bd\u30c3\u30c9\u3067\u30b5\u30fc\u30d3\u30b9\u30ed\u30b8\u30c3\u30af\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002\u6700\u521d\u306e\u30e1\u30bd\u30c3\u30c9\u3067\u3042\u308b shortenUrl \u306f\u3001URL\u306e\u77ed\u7e2e\u30ed\u30b8\u30c3\u30af\u3092\u542b\u307f\u307e\u3059\u30022\u756a\u76ee\u306e\u30e1\u30bd\u30c3\u30c9\u3067\u3042\u308b redirect \u306f\u3001\u30e6\u30fc\u30b6\u30fc\u3092\u5143\u306eURL\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u305f\u3081\u306e\u30ed\u30b8\u30c3\u30af\u3092\u542b\u307f\u307e\u3059\u3002\u307e\u305f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u5165\u529b\u3055\u308c\u308b\u30c7\u30fc\u30bf\u3092\u691c\u8a3c\u3059\u308b\u305f\u3081\u306e\u30c7\u30fc\u30bf\u8ee2\u9001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<h3>\u30ea\u30dd\u30b8\u30c8\u30ea\u3078\u306e\u30b5\u30fc\u30d3\u30b9\u30a2\u30af\u30bb\u30b9\u306e\u63d0\u4f9b<\/h3>\n<p>\u3053\u308c\u3089\u306e\u65b9\u6cd5\u3092\u5b9f\u88c5\u3059\u308b\u524d\u306b\u3001\u30b5\u30fc\u30d3\u30b9\u306b\u30ea\u30dd\u30b8\u30c8\u30ea\u3078\u306e\u30a2\u30af\u30bb\u30b9\u6a29\u9650\u3092\u4e0e\u3048\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u5bfe\u3057\u3066\u8aad\u307f\u66f8\u304d\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u6700\u521d\u306b\u3001src\/url\/url.service.ts\u3092\u958b\u3044\u3066\u304f\u3060\u3055\u3044\u3002 (Saisho ni, src\/url\/url.service.ts o hiraite kudasai.)<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">nano<\/span> src\/url\/url.service.ts<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u65e2\u5b58\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u3001\u4ee5\u4e0b\u306e\u30cf\u30a4\u30e9\u30a4\u30c8\u3055\u308c\u305f\u884c\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\n<p>\u4ee5\u4e0b\u306f\u3001\u65e5\u672c\u8a9e\u3067\u306e\u8868\u73fe\u4f8b\u3067\u3059\u3002<\/p>\n<p>src\/url\/url.service.ts \u2192 \u300csrc\/url\/url\u30b5\u30fc\u30d3\u30b9.ts\u300d<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>import { Injectable } from '@nestjs\/common';\r\n<mark>import { Repository } from 'typeorm';<\/mark>\r\n<mark>import { InjectRepository } from '@nestjs\/typeorm';<\/mark>\r\n<mark>import { Url } from '.\/url.entity';<\/mark>\r\n\r\n@Injectable()\r\nexport class UrlService {\r\n  <mark>constructor(<\/mark>\r\n    <mark>@InjectRepository(Url)<\/mark>\r\n    <mark>private repo: Repository&lt;Url&gt;,<\/mark>\r\n  <mark>) {}<\/mark>\r\n}\r\n<\/code><\/pre>\n<p>typeorm\u304b\u3089Repository\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3001@nestjs\/typeorm\u304b\u3089InjectRepository\u3001\u305d\u3057\u3066.\/url.entity\u304b\u3089Url\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>UrlService\u30af\u30e9\u30b9\u306e\u4e2d\u3067\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u4e2d\u3067\u3001\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u5909\u6570\u306erepo\u3092\u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u3057\u3066\u5ba3\u8a00\u3057\u307e\u3059\u3002\u305d\u306e\u5f8c\u3001repo\u306b\u306f\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u578bUrl\u3092\u6301\u3064Repository\u306e\u578b\u3092\u5272\u308a\u5f53\u3066\u307e\u3059\u3002\u305d\u3057\u3066\u3001repo\u5909\u6570\u306b@InjectRepository\u30c7\u30b3\u30ec\u30fc\u30bf\u3092\u4ed8\u3051\u3066\u3001Url\u3092\u5f15\u6570\u3068\u3057\u3066\u6e21\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u3066\u9589\u3058\u308b\u3002<\/p>\n<p>\u30b5\u30fc\u30d3\u30b9\u306f\u3001repo\u5909\u6570\u3092\u901a\u3058\u3066\u30ea\u30dd\u30b8\u30c8\u30ea\u3078\u306e\u30a2\u30af\u30bb\u30b9\u6a29\u3092\u6301\u3064\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30af\u30a8\u30ea\u3084TypeOrm\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u305d\u308c\u306b\u5bfe\u3057\u3066\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001\u975e\u540c\u671f\u30e1\u30bd\u30c3\u30c9\u3067\u3042\u308bshortenUrl\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306fURL\u3092\u5f15\u6570\u3068\u3057\u3066\u53d7\u3051\u53d6\u308a\u3001\u77ed\u7e2e\u3055\u308c\u305fURL\u3092\u8fd4\u3057\u307e\u3059\u3002\u30e1\u30bd\u30c3\u30c9\u306b\u4e0e\u3048\u3089\u308c\u308b\u30c7\u30fc\u30bf\u304c\u6709\u52b9\u304b\u3069\u3046\u304b\u3092\u691c\u8a3c\u3059\u308b\u305f\u3081\u306b\u3001\u30c7\u30fc\u30bf\u8ee2\u9001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u30af\u30e9\u30b9\u30d0\u30ea\u30c7\u30fc\u30bf\u3001\u30af\u30e9\u30b9\u30c8\u30e9\u30f3\u30b9\u30d5\u30a9\u30fc\u30de\u30fc\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<h3>\u30c7\u30fc\u30bf\u8ee2\u9001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08DTO\uff09\u306e\u4f5c\u6210<\/h3>\n<p>\u975e\u540c\u671f\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u6210\u3059\u308b\u524d\u306b\u3001shortenUrl\u975e\u540c\u671f\u30e1\u30bd\u30c3\u30c9\u3067\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u8ee2\u9001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u30c7\u30fc\u30bf\u8ee2\u9001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u306f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u9593\u3067\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5\u3092\u5b9a\u7fa9\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u6700\u521d\u306b\u3001URL\u30d5\u30a9\u30eb\u30c0\u5185\u306bDTOS\uff08\u30c7\u30fc\u30bf\u8ee2\u9001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\u30d5\u30a9\u30eb\u30c0\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">mkdir<\/span> src\/url\/dtos<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u305d\u308c\u304b\u3089\u3001\u305d\u306e\u30d5\u30a9\u30eb\u30c0\u5185\u306burl.dto.ts\u3068\u3044\u3046\u540d\u524d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">nano<\/span> src\/url\/dtos\/url.dto.ts<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u65b0\u3057\u3044\u30d5\u30a1\u30a4\u30eb\u306b\u6b21\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\u4ee5\u4e0b\u306e\u3082\u306e\u3092\u65e5\u672c\u8a9e\u3067\u8a00\u3044\u63db\u3048\u3066\u304f\u3060\u3055\u3044\uff08\uff11\u3064\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u63d0\u4f9b\u3057\u3066\u304f\u3060\u3055\u3044\uff09\uff1a<br \/>\nsrc\/url\/dto\/url.dto.ts\u30bd\u30fc\u30b9\/url\/dto\/url.dto.ts<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>import { IsString, IsNotEmpty } from 'class-validator';\r\n\r\nexport class ShortenURLDto {\r\n  @IsString()\r\n  @IsNotEmpty()\r\n  longUrl: string;\r\n}\r\n<\/code><\/pre>\n<p>class-validator\u304b\u3089IsString\u3068IsNotEmpty\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002\u6b21\u306b\u3001ShortenURLDto\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u3066\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002ShortenURLDto\u30af\u30e9\u30b9\u5185\u3067\u3001longUrl\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u4f5c\u6210\u3057\u3001\u305d\u306e\u578b\u3092\u6587\u5b57\u5217\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u3042\u306a\u305f\u306f\u307e\u305f\u3001longUrl\u30d7\u30ed\u30d1\u30c6\u30a3\u306bIsString\u3068IsNotEmpty\u30c7\u30b3\u30ec\u30fc\u30bf\u3092\u4ed8\u3051\u52a0\u3048\u307e\u3059\u3002\u3053\u308c\u3089\u306e\u30c7\u30b3\u30ec\u30fc\u30bf\u3092\u4f7f\u3063\u3066longUrl\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u308b\u3053\u3068\u3067\u3001\u5e38\u306blongUrl\u304c\u6587\u5b57\u5217\u3067\u3042\u308a\u3001\u304b\u3064\u7a7a\u3067\u306f\u306a\u3044\u3053\u3068\u304c\u4fdd\u8a3c\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u3066\u9589\u3058\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001src\/main.ts \u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">nano<\/span> src\/main.ts<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u65e2\u5b58\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u3001\u30cf\u30a4\u30e9\u30a4\u30c8\u3055\u308c\u305f\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\u30e1\u30a4\u30f3\u306e\u30d5\u30a1\u30a4\u30eb\u306fsrc\/main.ts\u3067\u3059\u3002<\/div>\n<pre class=\"post-pre\"><code><span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> NestFactory <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">'@nestjs\/core'<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> AppModule <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">'.\/app.module'<\/span><span class=\"token punctuation\">;<\/span>\r\n<mark><span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> ValidationPipe <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">'@nestjs\/common'<\/span><span class=\"token punctuation\">;<\/span><\/mark>\r\n\r\n<span class=\"token keyword\">async<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function\">bootstrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token keyword\">const<\/span> app <span class=\"token operator\">=<\/span> <span class=\"token keyword\">await<\/span> NestFactory<span class=\"token punctuation\">.<\/span><span class=\"token function\">create<\/span><span class=\"token punctuation\">(<\/span>AppModule<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n  <mark>app<span class=\"token punctuation\">.<\/span><span class=\"token function\">useGlobalPipes<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> <span class=\"token class-name\">ValidationPipe<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span> whitelist<span class=\"token operator\">:<\/span> <span class=\"token boolean\">true<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/mark>\r\n  <span class=\"token keyword\">await<\/span> app<span class=\"token punctuation\">.<\/span><span class=\"token function\">listen<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">3000<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<span class=\"token function\">bootstrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/code><\/pre>\n<p>\u3042\u306a\u305f\u306f\u3001\u30af\u30e9\u30b9\u30d0\u30ea\u30c7\u30fc\u30bf\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u7528\u3057\u3066\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30eb\u30fc\u30eb\u3092\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u5165\u529b\u3055\u308c\u308b\u3059\u3079\u3066\u306e\u30c7\u30fc\u30bf\u306b\u5f37\u5236\u3059\u308b\u305f\u3081\u306b\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30d1\u30a4\u30d7\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\uff08app\uff09\u3067useGlobalPipes\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001options\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u5171\u306bValidationPipe\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u6e21\u3057\u307e\u3059\u3002\u3053\u306eoptions\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u306f\u3001whitelist\u30d7\u30ed\u30d1\u30c6\u30a3\u3092true\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002useGlobalPipes\u30e1\u30bd\u30c3\u30c9\u306f\u3001ValidationPipe\u3092\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5168\u4f53\u3067\u30d0\u30a4\u30f3\u30c9\u3057\u3001\u3059\u3079\u3066\u306e\u30eb\u30fc\u30c8\u304c\u4e0d\u6b63\u306a\u30c7\u30fc\u30bf\u304b\u3089\u4fdd\u8b77\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002whitelist\u30d7\u30ed\u30d1\u30c6\u30a3\u3092true\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u30d0\u30ea\u30c7\u30fc\u30c8\u3055\u308c\u305f\uff08\u8fd4\u3055\u308c\u305f\uff09\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304b\u3089\u3001DTO\u3067\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u9664\u53bb\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u3066\u9589\u3058\u308b\u3002<\/p>\n<p>\u6b21\u306b\u3001\u30c7\u30fc\u30bf\u8ee2\u9001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092url.service.ts\u30d5\u30a1\u30a4\u30eb\u306b\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3001\u305d\u308c\u3092shortenUrl\u30e1\u30bd\u30c3\u30c9\u306b\u9069\u7528\u3057\u307e\u3059\u3002<\/p>\n<h3>\u77ed\u7e2eURL\u30e1\u30bd\u30c3\u30c9\u306e\u4f5c\u6210<\/h3>\n<p>\u30b7\u30e7\u30fc\u30c8URL\u30e1\u30bd\u30c3\u30c9\u306f\u3001URL\u306e\u77ed\u7e2e\u306b\u95a2\u3059\u308b\u307b\u3068\u3093\u3069\u306e\u51e6\u7406\u3092\u62c5\u5f53\u3057\u307e\u3059\u3002\u305d\u308c\u306f\u3001ShortenURLDto\u578b\u306eurl\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308a\u307e\u3059\u3002<\/p>\n<p>\u6700\u521d\u306b\u3001src\/url\/url.service.ts \u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u304f\u3060\u3055\u3044\u3002 (Mazu ni, src\/url\/url.service.ts fairu o aite kudasai.)<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">nano<\/span> src\/url\/url.service.ts<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u306b\u30cf\u30a4\u30e9\u30a4\u30c8\u3055\u308c\u305f\u884c\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\n<p>\u4ee5\u4e0b\u306f\u3001src\/url\/url.service.ts\u306e\u5185\u5bb9\u3092\u65e5\u672c\u8a9e\u3067\u8a00\u3044\u63db\u3048\u305f\u3082\u306e\u3067\u3059\u30021\u3064\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002<\/p>\n<p>src\/url\/url.service.ts\u306e\u5185\u5bb9\u3092\u6539\u5909\u3059\u308b\u3002<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>import {\r\n  <mark>BadRequestException,<\/mark>\r\n  Injectable,\r\n  <mark>NotFoundException,<\/mark>\r\n  <mark>UnprocessableEntityException,<\/mark>\r\n} from '@nestjs\/common';\r\nimport { Repository } from 'typeorm';\r\nimport { InjectRepository } from '@nestjs\/typeorm';\r\nimport { Url } from '.\/url.entity';\r\n<mark>import { ShortenURLDto } from '.\/dtos\/url.dto';<\/mark>\r\n<mark>import { nanoid } from 'nanoid';<\/mark>\r\n<mark>import { isURL } from 'class-validator';<\/mark>\r\n...\r\n<\/code><\/pre>\n<p>\u6700\u521d\u306b\u3001\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306b\u4f7f\u7528\u3059\u308b\u305f\u3081\u306b@nestjs\/common\u304b\u3089NotFoundExeception\u3001BadRequestException\u3001\u304a\u3088\u3073UnprocessableEntityException\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002\u6b21\u306b\u3001nanoid\u304b\u3089{nanoid}\u3001class-validator\u304b\u3089isURL\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002isURL\u306f\u3001\u63d0\u4f9b\u3055\u308c\u305flongUrl\u304c\u6709\u52b9\u306aURL\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u6700\u5f8c\u306b\u3001\u30c7\u30fc\u30bf\u306e\u691c\u8a3c\u306bShortenURLDto\u3092&#8217;.\/dtos\/url.dto&#8217;\u304b\u3089\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u4e0b\u306b\u3042\u308bUrlService \u30af\u30e9\u30b9\u306b\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>src\/url\/url.service.ts\u306e\u5185\u5bb9\u3092\u65e5\u672c\u8a9e\u3067\u8a00\u3044\u63db\u3048\u308b\u3068\u3001\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u300csrc\/url\/url.service.ts\u30d5\u30a1\u30a4\u30eb\u306f\u3001URL\u306b\u95a2\u9023\u3059\u308b\u30b5\u30fc\u30d3\u30b9\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u300d<\/div>\n<pre class=\"post-pre\"><code>...\r\nasync shortenUrl(url: ShortenURLDto) {}\r\n<\/code><\/pre>\n<p>\u6b21\u306b\u3001 shortenUrl \u30e1\u30bd\u30c3\u30c9\u306b\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\n<p>src\/url\/url.service.ts\u306e\u5185\u5bb9\u3092\u65e5\u672c\u8a9e\u3067\u8a00\u3044\u63db\u3048\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>src\/url\/url.service.ts\u306e\u6a5f\u80fd<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>...\r\n    const { longUrl } = url;\r\n\r\n    \/\/checks if longurl is a valid URL\r\n    if (!isURL(longUrl)) {\r\n      throw new BadRequestException('String Must be a Valid URL');\r\n    }\r\n\r\n    const urlCode = nanoid(10);\r\n    const baseURL = 'http:\/\/localhost:3000';\r\n\r\n    try {\r\n      \/\/check if the URL has already been shortened\r\n      let url = await this.repo.findOneBy({ longUrl });\r\n      \/\/return it if it exists\r\n      if (url) return url.shortUrl;\r\n\r\n      \/\/if it doesn't exist, shorten it\r\n      const shortUrl = `${baseURL}\/${urlCode}`;\r\n\r\n      \/\/add the new record to the database\r\n      url = this.repo.create({\r\n        urlCode,\r\n        longUrl,\r\n        shortUrl,\r\n      });\r\n\r\n      this.repo.save(url);\r\n      return url.shortUrl;\r\n    } catch (error) {\r\n      console.log(error);\r\n      throw new UnprocessableEntityException('Server Error');\r\n    }\r\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u30d6\u30ed\u30c3\u30af\u3067\u306f\u3001longUrl\u306furl\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304b\u3089\u5206\u89e3\u3055\u308c\u307e\u3057\u305f\u3002\u305d\u306e\u5f8c\u3001isURL\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001longUrl\u304c\u6709\u52b9\u306aURL\u3067\u3042\u308b\u304b\u3092\u691c\u8a3c\u3059\u308b\u30c1\u30a7\u30c3\u30af\u304c\u884c\u308f\u308c\u307e\u3059\u3002<\/p>\n<p>nanoid\u3092\u4f7f\u7528\u3057\u3066urlCode\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u3001nanoid\u306f21\u6587\u5b57\u306e\u30e6\u30cb\u30fc\u30af\u306a\u6587\u5b57\u5217\u3092\u751f\u6210\u3057\u307e\u3059\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u52d5\u4f5c\u3092\u4e0a\u66f8\u304d\u3059\u308b\u305f\u3081\u306b\u3001\u671b\u3080\u9577\u3055\u3092\u5f15\u6570\u3068\u3057\u3066\u6e21\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u306e\u5834\u5408\u3001URL\u3092\u3067\u304d\u308b\u3060\u3051\u77ed\u304f\u3057\u305f\u3044\u306e\u3067\u3001\u5024\u3068\u3057\u306610\u3092\u6e21\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001\u30d9\u30fc\u30b9URL\u304c\u5b9a\u7fa9\u3055\u308c\u307e\u3059\u3002\u30d9\u30fc\u30b9URL\u306f\u3001\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306e\u30a2\u30c9\u30ec\u30b9\u306e\u4e00\u8cab\u3057\u305f\u30eb\u30fc\u30c8\u3067\u3059\u3002\u958b\u767a\u3067\u306f\u3001\u305d\u308c\u306f\u30ed\u30fc\u30ab\u30eb\u30db\u30b9\u30c8\u30b5\u30fc\u30d0\u30fc\u3067\u3042\u308a\u3001\u672c\u756a\u3067\u306f\u30c9\u30e1\u30a4\u30f3\u540d\u3067\u3059\u3002\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u3001\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3067\u306flocalhost\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306e\u305f\u3081\u3001try-catch\u30d6\u30ed\u30c3\u30af\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u306e\u3059\u3079\u3066\u306e\u30b3\u30fc\u30c9\u3092\u542b\u3080\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>URL\u30922\u56de\u77ed\u7e2e\u3059\u308b\u3068\u30c7\u30fc\u30bf\u304c\u91cd\u8907\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u5bfe\u3057\u3066\u691c\u7d22\u30af\u30a8\u30ea\u304c\u5b9f\u884c\u3055\u308c\u3001URL\u304c\u5b58\u5728\u3059\u308b\u304b\u3069\u3046\u304b\u304c\u78ba\u8a8d\u3055\u308c\u307e\u3059\u3002\u5b58\u5728\u3059\u308b\u5834\u5408\u3001\u305d\u308c\u306b\u5bfe\u5fdc\u3059\u308b\u77ed\u7e2eURL\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306f\u3001\u30b3\u30fc\u30c9\u306f\u305d\u308c\u3092\u77ed\u7e2e\u3059\u308b\u305f\u3081\u306b\u9032\u884c\u3057\u307e\u3059\u3002\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306bURL\u306e\u30ec\u30b3\u30fc\u30c9\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u3001 baseURL\u3068urlCode\u3092\u9023\u7d50\u3057\u3066\u77ed\u7e2eURL\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u5f8c\u3001urlCode\u3001longUrl\u3001shortUrl\u3092\u4f7f\u7528\u3057\u3066url\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u305d\u306eurl\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306f\u3001\u30ea\u30dd\u30b8\u30c8\u30ea\u306esave\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u5f15\u6570\u3068\u3057\u3066\u6e21\u3059\u3053\u3068\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002\u305d\u3057\u3066\u3001shortUrl\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u6700\u5f8c\u306b\u3001\u3082\u3057\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u3001\u30a8\u30e9\u30fc\u306fcatch\u30d6\u30ed\u30c3\u30af\u3067\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u30ed\u30b0\u304c\u51fa\u529b\u3055\u308c\u3001UnprocessableEntityException\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u30b9\u30ed\u30fc\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306f\u3001\u3042\u306a\u305f\u306eurl.service.ts\u30d5\u30a1\u30a4\u30eb\u304c\u4eca\u5f8c\u3069\u306e\u3088\u3046\u306a\u5f62\u306b\u306a\u308b\u304b\u3067\u3059\u3002<\/p>\n<div>\n<p>src\/url\/url.service.ts\u3092\u65e5\u672c\u8a9e\u3067\u81ea\u7136\u306b\u8a00\u3044\u63db\u3048\u308b\u3068\u3001\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\uff1a<\/p>\n<p>\u30bd\u30fc\u30b9\/URL\/URL\u30b5\u30fc\u30d3\u30b9.ts<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>import {\r\n  BadRequestException,\r\n  Injectable,\r\n  NotFoundException,\r\n  UnprocessableEntityException,\r\n} from '@nestjs\/common';\r\nimport { Repository } from 'typeorm';\r\nimport { InjectRepository } from '@nestjs\/typeorm';\r\nimport { Url } from '.\/url.entity';\r\nimport { ShortenURLDto } from '.\/dtos\/url.dto';\r\nimport { nanoid } from 'nanoid';\r\nimport { isURL } from 'class-validator';\r\n\r\n@Injectable()\r\nexport class UrlService {\r\n  constructor(\r\n    @InjectRepository(Url)\r\n    private repo: Repository&lt;Url&gt;,\r\n  ) {}\r\n\r\n  async shortenUrl(url: ShortenURLDto) {\r\n    const { longUrl } = url;\r\n\r\n    \/\/checks if longurl is a valid URL\r\n    if (!isURL(longUrl)) {\r\n      throw new BadRequestException('String Must be a Valid URL');\r\n    }\r\n\r\n    const urlCode = nanoid(10);\r\n    const baseURL = 'http:\/\/localhost:3000';\r\n\r\n    try {\r\n      \/\/check if the URL has already been shortened\r\n      let url = await this.repo.findOneBy({ longUrl });\r\n      \/\/return it if it exists\r\n      if (url) return url.shortUrl;\r\n\r\n      \/\/if it doesn't exist, shorten it\r\n      const shortUrl = `${baseURL}\/${urlCode}`;\r\n\r\n      \/\/add the new record to the database\r\n      url = this.repo.create({\r\n        urlCode,\r\n        longUrl,\r\n        shortUrl,\r\n      });\r\n\r\n      this.repo.save(url);\r\n      return url.shortUrl;\r\n    } catch (error) {\r\n      console.log(error);\r\n      throw new UnprocessableEntityException('Server Error');\r\n    }\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3053\u3053\u3067URL\u306e\u77ed\u7e2e\u30ed\u30b8\u30c3\u30af\u306e\u6700\u521d\u306e\u90e8\u5206\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u6b21\u306b\u3001\u30b5\u30fc\u30d3\u30b9\u5185\u3067\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<h3>\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30e1\u30bd\u30c3\u30c9\u306e\u4f5c\u6210<\/h3>\n<p>\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30e1\u30bd\u30c3\u30c9\u306b\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u3092\u9577\u3044URL\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3055\u305b\u308b\u30ed\u30b8\u30c3\u30af\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u3060src\/url\/url\/service.ts\u30d5\u30a1\u30a4\u30eb\u5185\u306b\u304a\u3044\u3066\u3001UrlService\u30af\u30e9\u30b9\u306e\u6700\u5f8c\u306b\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u3001\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\n<p>src\/url\/url.service.ts\u3092\u65e5\u672c\u8a9e\u3067\u8a00\u3044\u63db\u3048\u308b\u3068:<\/p>\n<p>\u300csrc\/url\/url.service.ts\u300d<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>...\r\n  async redirect(urlCode: string) {\r\n    try {\r\n      const url = await this.repo.findOneBy({ urlCode });\r\n      if (url) return url;\r\n    } catch (error) {\r\n      console.log(error);\r\n      throw new NotFoundException('Resource Not Found');\r\n    }\r\n  }\r\n<\/code><\/pre>\n<p>\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30e1\u30bd\u30c3\u30c9\u306f\u3001urlCode\u3092\u5f15\u6570\u3068\u3057\u3066\u53d7\u3051\u53d6\u308a\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u5185\u306b\u4e00\u81f4\u3059\u308burlCode\u3092\u6301\u3064\u30ea\u30bd\u30fc\u30b9\u3092\u898b\u3064\u3051\u3088\u3046\u3068\u3057\u307e\u3059\u3002\u3082\u3057\u30ea\u30bd\u30fc\u30b9\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306f\u3001\u305d\u306e\u30ea\u30bd\u30fc\u30b9\u3092\u8fd4\u3057\u307e\u3059\u3002\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306f\u3001NotFoundException\u30a8\u30e9\u30fc\u3092\u30b9\u30ed\u30fc\u3057\u307e\u3059\u3002<\/p>\n<p>\u3042\u306a\u305f\u306e\u5b8c\u6210\u3057\u305furl.service.ts\u30d5\u30a1\u30a4\u30eb\u306f\u3001\u3053\u308c\u304b\u3089\u306f\u3053\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<div>\n<p>\u4ee5\u4e0b\u306fsrc\/url\/url.service.ts\u306e\u65e5\u672c\u8a9e\u306b\u3088\u308b\u8a00\u3044\u63db\u3048\u3067\u3059\uff1a<\/p>\n<p>\u30bd\u30fc\u30b9\/url\/url.service.ts<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>import {\r\n  BadRequestException,\r\n  Injectable,\r\n  NotFoundException,\r\n  UnprocessableEntityException,\r\n} from '@nestjs\/common';\r\nimport { Repository } from 'typeorm';\r\nimport { InjectRepository } from '@nestjs\/typeorm';\r\nimport { Url } from '.\/url.entity';\r\nimport { ShortenURLDto } from '.\/dtos\/url.dto';\r\nimport { nanoid } from 'nanoid';\r\nimport { isURL } from 'class-validator';\r\n\r\n@Injectable()\r\nexport class UrlService {\r\n  constructor(\r\n    @InjectRepository(Url)\r\n    private repo: Repository&lt;Url&gt;,\r\n  ) {}\r\n\r\n  async shortenUrl(url: ShortenURLDto) {\r\n    const { longUrl } = url;\r\n\r\n    \/\/checks if longurl is a valid URL\r\n    if (!isURL(longUrl)) {\r\n      throw new BadRequestException('String Must be a Valid URL');\r\n    }\r\n\r\n    const urlCode = nanoid(10);\r\n    const baseURL = 'http:\/\/localhost:3000';\r\n\r\n    try {\r\n      \/\/check if the URL has already been shortened\r\n      let url = await this.repo.findOneBy({ longUrl });\r\n      \/\/return it if it exists\r\n      if (url) return url.shortUrl;\r\n\r\n      \/\/if it doesn't exist, shorten it\r\n      const shortUrl = `${baseURL}\/${urlCode}`;\r\n\r\n      \/\/add the new record to the database\r\n      url = this.repo.create({\r\n        urlCode,\r\n        longUrl,\r\n        shortUrl,\r\n      });\r\n\r\n      this.repo.save(url);\r\n      return url.shortUrl;\r\n    } catch (error) {\r\n      console.log(error);\r\n      throw new UnprocessableEntityException('Server Error');\r\n    }\r\n  }\r\n\r\n  async redirect(urlCode: string) {\r\n    try {\r\n      const url = await this.repo.findOneBy({ urlCode });\r\n      if (url) return url;\r\n    } catch (error) {\r\n      console.log(error);\r\n      throw new NotFoundException('Resource Not Found');\r\n    }\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u3066\u9589\u3058\u308b\u3002<\/p>\n<p>\u3042\u306a\u305f\u306eURL\u77ed\u7e2e\u306e\u30ed\u30b8\u30c3\u30af\u306f\u3001URL\u3092\u77ed\u7e2e\u3059\u308b\u305f\u3081\u306e\u30e1\u30bd\u30c3\u30c9\u3068\u3001\u77ed\u7e2e\u3055\u308c\u305fURL\u3092\u5143\u306eURL\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u305f\u3081\u306e\u5225\u306e\u30e1\u30bd\u30c3\u30c9\u306e2\u3064\u3067\u5b8c\u4e86\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u306f\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u30af\u30e9\u30b9\u306b\u3053\u308c\u3089\u306e2\u3064\u306e\u30e1\u30bd\u30c3\u30c9\u306e\u305f\u3081\u306e\u30eb\u30fc\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30b9\u30c6\u30c3\u30d74 \u2014 \u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u30ed\u30b8\u30c3\u30af\u306e\u5b9f\u88c5<\/h2>\n<p>\u3053\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u306f\u30012\u3064\u306e\u30eb\u30fc\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u4f5c\u6210\u3057\u307e\u3059\u30021\u3064\u306f\u77ed\u7e2e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u51e6\u7406\u3059\u308b\u305f\u3081\u306ePOST\u30eb\u30fc\u30c8\u30cf\u30f3\u30c9\u30e9\u3067\u3042\u308a\u3001\u3082\u30461\u3064\u306f\u30ea\u30c0\u30a4\u30ec\u30af\u30b7\u30e7\u30f3\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u51e6\u7406\u3059\u308b\u305f\u3081\u306eGET\u30eb\u30fc\u30c8\u30cf\u30f3\u30c9\u30e9\u3067\u3059\u3002<\/p>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u30af\u30e9\u30b9\u3067\u30eb\u30fc\u30c8\u3092\u5b9f\u88c5\u3059\u308b\u524d\u306b\u3001\u30b5\u30fc\u30d3\u30b9\u3092\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u5229\u7528\u53ef\u80fd\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u6700\u521d\u306b\u3001src\/url\/url.controller.ts\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">nano<\/span> src\/url\/url.controller.ts<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u306b\u30cf\u30a4\u30e9\u30a4\u30c8\u3055\u308c\u305f\u884c\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\u4ee5\u4e0b\u306f\u3001\u65e5\u672c\u8a9e\u3067\u306e\u4e00\u3064\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3059\u3002<br \/>\nsrc\/url\/url.controller.ts -&gt; src\/url\/url.controller.ts\u3067\u3059\u3002<\/div>\n<pre class=\"post-pre\"><code>import { Controller } from '@nestjs\/common';\r\n<mark>import { UrlService } from '.\/url.service';<\/mark>\r\n\r\n@Controller('url')\r\nexport class UrlController {\r\n  <mark>constructor(private service: UrlService) {}<\/mark>\r\n}\r\n<\/code><\/pre>\n<p>\u6700\u521d\u306b\u3001.\/url.service\u304b\u3089UrlService\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002\u6b21\u306b\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u30af\u30e9\u30b9\u3067\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u30fc\u3092\u5ba3\u8a00\u3057\u3001\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u5909\u6570\u3067\u3042\u308bservice\u3092\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3068\u3057\u3066\u521d\u671f\u5316\u3057\u307e\u3059\u3002service\u306e\u578b\u306fUrlService\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u73fe\u5728\u3001Controller\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u306b\u306f\u6587\u5b57\u5217\u306e &#8216;url&#8217; \u304c\u5f15\u6570\u3068\u3057\u3066\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u304clocalhost\/3000\/url\/route\u306b\u5bfe\u3057\u3066\u306e\u307f\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u51e6\u7406\u3059\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002\u3053\u306e\u52d5\u4f5c\u306b\u3088\u308a\u3001URL\u306e\u77ed\u7e2e\u30ed\u30b8\u30c3\u30af\u306b\u30d0\u30b0\u304c\u767a\u751f\u3057\u307e\u3059\u3002\u77ed\u7e2e\u3055\u308c\u305fURL\u306b\u306f\u30d9\u30fc\u30b9URL\uff08localhost:3000\uff09\u3068URL\u30b3\u30fc\u30c9\uff08wyt4_uyP-Il\uff09\u304c\u542b\u307e\u308c\u3066\u304a\u308a\u3001\u3053\u308c\u304c\u65b0\u3057\u3044URL\uff08localhost:3000\/wyt4_uyP-Il\uff09\u3092\u5f62\u6210\u3057\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306f\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u51e6\u7406\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u305a\u3001\u77ed\u7e2e\u30ea\u30f3\u30af\u306f404 Not Found\u306e\u30a8\u30e9\u30fc\u3092\u8fd4\u3057\u307e\u3059\u3002\u3053\u308c\u3092\u89e3\u6c7a\u3059\u308b\u306b\u306f\u3001Controller\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u304b\u3089 &#8216;url&#8217; \u5f15\u6570\u3092\u524a\u9664\u3057\u3001\u5404\u30cf\u30f3\u30c9\u30e9\u30fc\u306b\u500b\u5225\u306e\u30eb\u30fc\u30c8\u3092\u5b9f\u88c5\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>&#8216;UrlController&#8217;\u3067\u306f\u3001&#8217;url&#8217;\u5f15\u6570\u3092\u524a\u9664\u3057\u305f\u5f8c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<div>\u4ee5\u4e0b\u306e\u6587\u3092\u65e5\u672c\u8a9e\u3067\u81ea\u7136\u306b\u8a00\u3044\u63db\u3048\u3066\u304f\u3060\u3055\u3044\u30021\u3064\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3060\u3051\u5fc5\u8981\u3067\u3059\uff1a<br \/>\nsrc\/url\/url.controller.ts\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u300csrc\/url\/url.controller.ts\u300d<\/p>\n<\/div>\n<pre class=\"post-pre\"><code><mark>@Controller()<\/mark>\r\nexport class UrlController {\r\n  constructor(private service: UrlService) {}\r\n}\r\n<\/code><\/pre>\n<p>\u307e\u3060src\/url\/url.controller.ts\u30d5\u30a1\u30a4\u30eb\u306b\u3044\u308b\u72b6\u614b\u3067\u3001\u30cf\u30a4\u30e9\u30a4\u30c8\u3055\u308c\u305f\u9805\u76ee\u3092import\u6587\u306b\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\u4ee5\u4e0b\u306e\u6587\u3092\u65e5\u672c\u8a9e\u3067\u8a00\u3044\u63db\u3048\u3066\u304f\u3060\u3055\u3044\uff081\u3064\u306e\u9078\u629e\u80a2\u3067\uff09\uff1a<br \/>\nsrc\/url\/url.controller.tssrc\/url\/url.controller.ts<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>import { <mark>Body,<\/mark> Controller, <mark>Get, Param, Post, Res<\/mark> } from '@nestjs\/common';\r\nimport { UrlService } from '.\/url.service';\r\n<mark>import { ShortenURLDto } from '.\/dtos\/url.dto';<\/mark>\r\n<\/code><\/pre>\n<p>@nestjs\/common\u304b\u3089Body\u3001Get\u3001Param\u3001Post\u3001Res\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3001.\/dtos\/url.dto\u304b\u3089ShortenURLDto\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002\u30c7\u30b3\u30ec\u30fc\u30bf\u306f\u3001\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u8ffd\u52a0\u3059\u308b\u306b\u3064\u308c\u3066\u3055\u3089\u306b\u5b9a\u7fa9\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001POST\u30eb\u30fc\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u5b9a\u7fa9\u3059\u308b\u305f\u3081\u306b\u3001\u4ee5\u4e0b\u306e\u884c\u3092\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u4e0b\u306bUrlController\u306b\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\n<p>\u4ee5\u4e0b\u306f\u3001src\/url\/url.controller.ts\u3092\u65e5\u672c\u8a9e\u3067\u81ea\u7136\u306b\u8ff0\u3079\u305f\u3082\u306e\u3067\u3059\u3002\uff081\u3064\u306e\u9078\u629e\u80a2\u3067\u3059\uff09<\/p>\n<p>\u300csrc\/url\/url.controller.ts\u300d\u3092\u65e5\u672c\u8a9e\u3067\u8a00\u3044\u63db\u3048\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>...\r\n  @Post('shorten')\r\n  shortenUrl(\r\n    @Body()\r\n    url: ShortenURLDto,\r\n  ) {\r\n    return this.service.shortenUrl(url);\r\n  }\r\n<\/code><\/pre>\n<p>ShortenURLDto\u306e\u578b\u3092\u6301\u3064url\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308bshortenUrl\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u30ea\u30af\u30a8\u30b9\u30c8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304b\u3089\u30dc\u30c7\u30a3\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u62bd\u51fa\u3057\u3001url\u5909\u6570\u306b\u305d\u306e\u5024\u3092\u683c\u7d0d\u3059\u308b\u305f\u3081\u3001url\u306b\u306fBody\u30c7\u30b3\u30ec\u30fc\u30bf\u3092\u4ed8\u3051\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u5f8c\u3001`Post`\u30c7\u30b3\u30ec\u30fc\u30bf\u3092\u4f7f\u3063\u3066\u30e1\u30bd\u30c3\u30c9\u5168\u4f53\u306b\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u3001\u5f15\u6570\u3068\u3057\u3066`&#8217;shorten&#8217;`\u3092\u6e21\u3057\u307e\u3059\u3002\u3053\u306e\u30cf\u30f3\u30c9\u30e9\u306f\u3001`localhost:\/shorten`\u306b\u9001\u4fe1\u3055\u308c\u305f\u3059\u3079\u3066\u306ePost\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u51e6\u7406\u3057\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u30b5\u30fc\u30d3\u30b9\u306e`shortenUrl`\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001\u5f15\u6570\u3068\u3057\u3066url\u3092\u6e21\u3057\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001GET\u30eb\u30fc\u30c8\u306e\u30cf\u30f3\u30c9\u30e9\u30fc\u3092\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u305f\u3081\u306b\u3001\u4ee5\u4e0b\u306e\u884c\u3092POST\u30eb\u30fc\u30c8\u306e\u4e0b\u306b\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\n<p>src\/url\/url.controller.ts\u306e\u5185\u5bb9\u3092\u65e5\u672c\u8a9e\u3067\u30cd\u30a4\u30c6\u30a3\u30d6\u306b\u8a00\u3044\u63db\u3048\u307e\u3059\u3002<\/p>\n<p>\u30d1\u30b9 src\/url\/url.controller.ts \u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u65e5\u672c\u8a9e\u3067\u66f8\u304d\u63db\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>...\r\n  @Get(':code')\r\n  async redirect(\r\n    @Res() res,\r\n    @Param('code')\r\n    code: string,\r\n  ) {\r\n    const url = await this.service.redirect(code);\r\n\r\n    return res.redirect(url.longUrl);\r\n  }\r\n<\/code><\/pre>\n<p>\u4ee5\u4e0b\u306e\u5185\u5bb9\u3092\u65e5\u672c\u8a9e\u3067\u8868\u73fe\u3059\u308b\u3068\uff1a<\/p>\n<p>\u300c\u3042\u306a\u305f\u306f2\u3064\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\uff08Res\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u3067\u6ce8\u91c8\u3092\u4ed8\u3051\u305fres\u3068Param\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u3067\u6ce8\u91c8\u3092\u4ed8\u3051\u305fcode\uff09\u3092\u6301\u3064\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002Res\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u306f\u3001\u6ce8\u91c8\u304c\u4ed8\u3051\u3089\u308c\u305f\u30af\u30e9\u30b9\u3092Express\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5909\u63db\u3057\u3001Express\u306e\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30e1\u30bd\u30c3\u30c9\u306e\u3088\u3046\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u56fa\u6709\u306e\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002Param\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc\u306f\u3001req\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304b\u3089params\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u62bd\u51fa\u3057\u3001\u305d\u306e\u5024\u3067\u6ce8\u91c8\u304c\u4ed8\u3051\u3089\u308c\u305f\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u88dc\u5b8c\u3057\u307e\u3059\u3002\u300d<\/p>\n<p>Get\u30c7\u30b3\u30ec\u30fc\u30bf\u3092\u4f7f\u3063\u3066\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30e1\u30bd\u30c3\u30c9\u306b\u6ce8\u91c8\u3092\u3064\u3051\u3001\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9\u30d1\u30e9\u30e1\u30fc\u30bf&#8217;:code&#8217;\u3092\u6e21\u3057\u307e\u3059\u3002\u6b21\u306b\u3001&#8217;code&#8217;\u3092\u5f15\u6570\u3068\u3057\u3066Param\u30c7\u30b3\u30ec\u30fc\u30bf\u306b\u6e21\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001\u30b5\u30fc\u30d3\u30b9\u306e\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001\u7d50\u679c\u3092\u5f85\u6a5f\u3057\u3066\u5909\u6570\u300curl\u300d\u306b\u683c\u7d0d\u3057\u307e\u3059\u3002<\/p>\n<p>\u6700\u5f8c\u306b\u3001res.redirect()\u3092\u8fd4\u3057\u3001url.longUrl\u3092\u5f15\u6570\u3068\u3057\u3066\u6e21\u3057\u307e\u3059\u3002\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u3001localhost:\/code\u307e\u305f\u306f\u77ed\u7e2eURL\u3078\u306eGET\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u51e6\u7406\u3057\u307e\u3059\u3002<\/p>\n<p>\u3042\u306a\u305f\u306esrc\/url\/url.controller.ts\u30d5\u30a1\u30a4\u30eb\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<div>src\/url\/url.controller.ts\u306e\u5185\u5bb9\u3092\u65e5\u672c\u8a9e\u3067\u8a00\u3044\u63db\u3048\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/div>\n<pre class=\"post-pre\"><code>import { Body, Controller, Get, Param, Post, Res } from '@nestjs\/common';\r\nimport { UrlService } from '.\/url.service';\r\nimport { ShortenURLDto } from '.\/dtos\/url.dto';\r\n\r\n@Controller()\r\nexport class UrlController {\r\n  constructor(private service: UrlService) {}\r\n\r\n  @Post('shorten')\r\n  shortenUrl(\r\n    @Body()\r\n    url: ShortenURLDto,\r\n  ) {\r\n    return this.service.shortenUrl(url);\r\n  }\r\n\r\n  @Get(':code')\r\n  async redirect(\r\n    @Res() res,\r\n    @Param('code')\r\n    code: string,\r\n  ) {\r\n    const url = await this.service.redirect(code);\r\n\r\n    return res.redirect(url.longUrl);\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u3066\u9589\u3058\u308b\u3002<\/p>\n<p>POST\u3068GET\u306e\u30eb\u30fc\u30c8\u30cf\u30f3\u30c9\u30e9\u30fc\u3092\u5b9a\u7fa9\u3057\u305f\u306e\u3067\u3001URL\u77ed\u7e2e\u30b5\u30fc\u30d3\u30b9\u304c\u5b8c\u5168\u306b\u6a5f\u80fd\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u306f\u3001\u30c6\u30b9\u30c8\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30b9\u30c6\u30c3\u30d75 \u2014 URL\u77ed\u7e2e\u30c4\u30fc\u30eb\u306e\u30c6\u30b9\u30c8<\/h2>\n<p>\u3053\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u306f\u3001\u524d\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u5b9a\u7fa9\u3057\u305fURL\u77ed\u7e2e\u30b5\u30fc\u30d3\u30b9\u3092\u30c6\u30b9\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u6700\u521d\u306b\u3001\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8d77\u52d5\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">npm<\/span> run start<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u4ee5\u4e0b\u306e\u51fa\u529b\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>[Nest] 12640 &#8211; 06\/08\/2022, 16:20:04 LOG [NestFactory] Starting Nest application&#8230; [Nest] 12640 &#8211; 06\/08\/2022, 16:20:07 LOG [InstanceLoader] AppModule dependencies initialized +2942ms [Nest] 12640 &#8211; 06\/08\/2022, 16:20:07 LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms [Nest] 12640 &#8211; 06\/08\/2022, 16:20:08 LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +257ms [Nest] 12640 &#8211; 06\/08\/2022, 16:20:08 LOG [InstanceLoader] TypeOrmModule dependencies initialized +2ms [Nest] 12640 &#8211; 06\/08\/2022, 16:20:08 LOG [InstanceLoader] UrlModule dependencies initialized +4ms [Nest] 12640 &#8211; 06\/08\/2022, 16:20:08 LOG [RoutesResolver] UrlController {\/}: +68ms [Nest] 12640 &#8211; 06\/08\/2022, 16:20:08 LOG [RouterExplorer] Mapped {\/shorten, POST} route +7ms [Nest] 12640 &#8211; 06\/08\/2022, 16:20:08 LOG [RouterExplorer] Mapped {\/:code, GET} route +2ms [Nest] 12640 &#8211; 06\/08\/2022, 16:20:08 LOG [NestApplication] Nest application successfully started +7ms<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u4ee5\u4e0b\u306e\u30c7\u30fc\u30bf\u307e\u305f\u306f\u4efb\u610f\u306e\u30c7\u30fc\u30bf\u3092\u4f7f\u7528\u3057\u3066\u3001curl\u307e\u305f\u306f\u304a\u597d\u307f\u306eAPI\u30c6\u30b9\u30c8\u30c4\u30fc\u30eb\u3067http:\/\/localhost:3000\/shorten\u306bPOST\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u884c\u3046\u305f\u3081\u306b\u3001\u65b0\u3057\u3044\u7aef\u672b\u3092\u958b\u3044\u3066\u304f\u3060\u3055\u3044\u3002curl\u306e\u4f7f\u7528\u65b9\u6cd5\u306b\u3064\u3044\u3066\u306e\u8a73\u7d30\u306f\u3001\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u8aac\u660e\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u306ePOST\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306b\u3001\u3053\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">curl<\/span> <span class=\"token parameter variable\">-d<\/span> <span class=\"token string\">&#8220;{<span class=\"token entity\" title=\"\\&quot;\">\\&#8221;<\/span>longUrl<span class=\"token entity\" title=\"\\&quot;\">\\&#8221;<\/span>:<span class=\"token entity\" title=\"\\&quot;\">\\&#8221;<\/span>http:\/\/llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk<span class=\"token entity\" title=\"\\&quot;\">\\&#8221;<\/span>}&#8221;<\/span> <span class=\"token parameter variable\">-H<\/span> <span class=\"token string\">&#8220;Content-Type: application\/json&#8221;<\/span> http:\/\/localhost:3000\/shorten<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u300c-d\u300d\u30d5\u30e9\u30b0\u306f\u3001HTTP POST\u30ea\u30af\u30a8\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u767b\u9332\u3057\u3001\u300c-H\u300d\u30d5\u30e9\u30b0\u306fHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u30d8\u30c3\u30c0\u30fc\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u3053\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u9577\u3044URL\u304c\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u9001\u4fe1\u3055\u308c\u3001\u77ed\u7e2eURL\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u4f8b\u306e\u3088\u3046\u306a\u3001\u77ed\u7e2eURL\u304c\u8fd4\u4fe1\u3068\u3057\u3066\u63d0\u4f9b\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>http:\/\/localhost:3000\/MWBNHDiloW\r\n<\/code><\/pre>\n<p>\u6700\u5f8c\u306b\u3001\u77ed\u7e2eURL\u3092\u30b3\u30d4\u30fc\u3057\u3066\u30d6\u30e9\u30a6\u30b6\u306b\u30ea\u30f3\u30af\u3092\u8cbc\u308a\u4ed8\u3051\u307e\u3059\u3002\u305d\u306e\u5f8c\u3001ENTER\u3092\u62bc\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3059\u308b\u3068\u5143\u306e\u30ea\u30bd\u30fc\u30b9\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001NestJS\u3092\u4f7f\u3063\u3066URL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u8ffd\u52a0\u3059\u308c\u3070\u3001\u4e00\u822c\u516c\u958b\u7528\u306b\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u8a73\u7d30\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306fGithub\u3067\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>NestJS\u306f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u3088\u308a\u5b89\u5168\u6027\u3001\u4fdd\u5b88\u6027\u3001\u62e1\u5f35\u6027\u306e\u9ad8\u3044\u3082\u306e\u306b\u3059\u308b\u305f\u3081\u306e\u578b\u5b89\u5168\u6027\u3068\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002\u8a73\u3057\u304f\u306f\u3001NestJS\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8457\u8005\u306f\u3001Write for Donations\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4e00\u74b0\u3068\u3057\u3066\u3001\u5bc4\u4ed8\u306e\u53d7\u9818\u5148\u3068\u3057\u3066Tech Education Fund\u3092\u9078\u629e\u3057\u307e\u3057\u305f\u3002 \u4ee5\u4e0b\u306e\u6587\u7ae0\u3092\u65e5\u672c\u8a9e\u3067\u81ea\u7136\u306a\u8a00\u3044\u65b9\u3067\u8a00\u3044\u63db\u3048\u308b\uff081\u3064\u306e\u9078\u629e\u80a2\u306e\u307f\uff09\uff1a \u30a4\u30f3\u30c8\u30ed [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[26,61],"class_list":["post-300","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-26","tag-61"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5 - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/ja\/blog\/nodejs\u3084nestjs\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aurl\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5\" \/>\n<meta property=\"og:description\" content=\"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/ja\/blog\/nodejs\u3084nestjs\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aurl\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-04T08:49:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T13:27:54+00:00\" \/>\n<meta name=\"author\" content=\"\u7d50\u8863, \u6625\u82b1\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u7d50\u8863, \u6625\u82b1\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"58\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/\",\"name\":\"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\"},\"datePublished\":\"2023-08-04T08:49:36+00:00\",\"dateModified\":\"2025-07-31T13:27:54+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/e52a686063ac76fd8cc6f539d41497ac\"},\"description\":\"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/ja\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"ja\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/e52a686063ac76fd8cc6f539d41497ac\",\"name\":\"\u7d50\u8863, \u6625\u82b1\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c74c6e2eb915a3c8e795b3934aa25a7333e0b38e7f1c7baf52785286ad51105e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c74c6e2eb915a3c8e795b3934aa25a7333e0b38e7f1c7baf52785286ad51105e?s=96&d=mm&r=g\",\"caption\":\"\u7d50\u8863, \u6625\u82b1\"},\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/author\/yuiharuka\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5 - Blog - Silicon Cloud","description":"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/ja\/blog\/nodejs\u3084nestjs\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aurl\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\/","og_locale":"ja_JP","og_type":"article","og_title":"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5","og_description":"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","og_url":"https:\/\/www.silicloud.com\/ja\/blog\/nodejs\u3084nestjs\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aurl\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-08-04T08:49:36+00:00","article_modified_time":"2025-07-31T13:27:54+00:00","author":"\u7d50\u8863, \u6625\u82b1","twitter_card":"summary_large_image","twitter_misc":{"\u57f7\u7b46\u8005":"\u7d50\u8863, \u6625\u82b1","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"58\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/","url":"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/","name":"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website"},"datePublished":"2023-08-04T08:49:36+00:00","dateModified":"2025-07-31T13:27:54+00:00","author":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/e52a686063ac76fd8cc6f539d41497ac"},"description":"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/ja\/blog\/"},{"@type":"ListItem","position":2,"name":"NodeJS\u3084NestJS\u3092\u4f7f\u7528\u3057\u3066\u3001\u578b\u5b89\u5168\u306aURL\u77ed\u7e2e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u65b9\u6cd5"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website","url":"https:\/\/www.silicloud.com\/ja\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"ja"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/e52a686063ac76fd8cc6f539d41497ac","name":"\u7d50\u8863, \u6625\u82b1","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c74c6e2eb915a3c8e795b3934aa25a7333e0b38e7f1c7baf52785286ad51105e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c74c6e2eb915a3c8e795b3934aa25a7333e0b38e7f1c7baf52785286ad51105e?s=96&d=mm&r=g","caption":"\u7d50\u8863, \u6625\u82b1"},"url":"https:\/\/www.silicloud.com\/ja\/blog\/author\/yuiharuka\/"},{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/nodejs%e3%82%84nestjs%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e5%9e%8b%e5%ae%89%e5%85%a8%e3%81%aaurl%e7%9f%ad%e7%b8%ae%e3%83%84%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b%e6%96%b9\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/comments?post=300"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/300\/revisions"}],"predecessor-version":[{"id":38843,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/300\/revisions\/38843"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/media?parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/categories?post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/tags?post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}