<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Node.js on oinume journal</title>
		<link>https://journal.lampetty.net/tags/node.js/</link>
		<description>Recent content in Node.js on oinume journal</description>
		<generator>Hugo</generator>
		<language>ja</language>
		
		
		
		
			<lastBuildDate>Sat, 09 Apr 2016 21:43:56 +0900</lastBuildDate>
		
			<atom:link href="https://journal.lampetty.net/tags/node.js/rss.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>3 things I do after installing Nodejs</title>
				<link>https://journal.lampetty.net/posts/3-things-i-do-after-installing-nodejs/</link>
				<pubDate>Sat, 09 Apr 2016 21:43:56 +0900</pubDate>
				<guid>https://journal.lampetty.net/posts/3-things-i-do-after-installing-nodejs/</guid>
				<description>&lt;h3 id=&#34;installing-latest-npm&#34;&gt;Installing latest npm&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ npm install -g npm@latest&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;disabling-npms-progress-bar&#34;&gt;Disabling npm’s progress bar&lt;/h3&gt;&#xA;&lt;p&gt;Disabling progress bar for faster &lt;code&gt;npm install&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ npm set progress=false&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;See &lt;a href=&#34;https://github.com/npm/npm/issues/11283#issuecomment-175246823&#34;&gt;Progress bar noticeably slows down npm install · Issue #11283 · npm/npm&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;installing-npm-check&#34;&gt;Installing &lt;code&gt;npm-check&lt;/code&gt;&lt;/h3&gt;&#xA;&lt;p&gt;&lt;code&gt;npm-check&lt;/code&gt; checks outdated, incorrect, and unused dependencies.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ npm install -g npm-check&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&#34;https://www.npmjs.com/package/npm-check&#34;&gt;www.npmjs.com&lt;/a&gt;&lt;/p&gt;&#xA;</description>
			</item>
			<item>
				<title>TypeScriptでNode.jsのexpressを使ってHello worldしてみる</title>
				<link>https://journal.lampetty.net/posts/using-express-with-typescript/</link>
				<pubDate>Tue, 18 Feb 2014 02:03:03 +0900</pubDate>
				<guid>https://journal.lampetty.net/posts/using-express-with-typescript/</guid>
				<description>&lt;p&gt;TypeScriptでexpressを使ってHello worldしてみた。けっこうはまったのでメモメモ。使ってるTypeScriptのバージョンは1.0.1。&lt;/p&gt;&#xA;&lt;h1 id=&#34;準備&#34;&gt;準備&lt;/h1&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;npm install -g typescript&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;npm install --save express&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id=&#34;試しにコンパイル&#34;&gt;試しにコンパイル&lt;/h1&gt;&#xA;&lt;p&gt;こんな感じのコードを書いてコンパイルしてみる。&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ tsc --module commonjs hello.ts&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;コンパイルエラーが...(；´Д｀)&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;./typescript-sample/server/hello.ts(1,1): error TS2071: Unable to resolve external module &amp;#39;&amp;#39;express&amp;#39;&amp;#39;.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;./typescript-sample/server/hello.ts(1,1): error TS2072: Module cannot be aliased to a non-module type.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;./typescript-sample/server/hello.ts(2,1): error TS2071: Unable to resolve external module &amp;#39;&amp;#39;http&amp;#39;&amp;#39;.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;./typescript-sample/server/hello.ts(2,1): error TS2072: Module cannot be aliased to a non-module type.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;./typescript-sample/server/hello.ts(5,11): error TS2088: Cannot invoke an expression whose type lacks a call signature.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;./typescript-sample/server/hello.ts(6,17): error TS2095: Could not find symbol &amp;#39;process&amp;#39;.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id=&#34;定義ファイルをコピー&#34;&gt;定義ファイルをコピー&lt;/h1&gt;&#xA;&lt;p&gt;いろいろググったところ、expressやNode.jsの標準ライブラリの定義ファイルみたいなものが必要らしいので、&lt;a href=&#34;https://github.com/soywiz/DefinitelyTyped&#34;&gt;ここ&lt;/a&gt;から以下の2つをhello.tsと同じディレクトリに配置する。&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;node/node.d.ts&lt;/li&gt;&#xA;&lt;li&gt;express/express.d.ts&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;なお、&lt;a href=&#34;https://github.com/soywiz/DefinitelyTyped/blob/master/express/express.d.ts#L13&#34;&gt;express.d.tsのL13&lt;/a&gt;は&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/// &amp;lt;reference path=&amp;#34;node.d.ts&amp;#34; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;のように修正する必要がある。(ディレクトリ構造が違うため。これ、DefinitelyTypedのディレクトリ構造のままじゃ駄目なのかなー？)&lt;/p&gt;&#xA;&lt;h3 id=&#34;追記&#34;&gt;追記&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ npm install -g tsd&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ tsd query express --save --resolve --action install&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;して、hello.ts に&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/// &amp;lt;reference path=&amp;#34;typings/tsd.d.ts&amp;#34; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;を追記することで型定義ファイルを参照することができるようになった。vvakame さんありがとうございます！&lt;/p&gt;&#xA;&lt;h1 id=&#34;もう一度コンパイル&#34;&gt;もう一度コンパイル&lt;/h1&gt;&#xA;&lt;p&gt;これでもう一回コンパイルしてみる。今度は成功するはず。&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ tsc --module commonjs hello.ts&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;あとは生成された hello.js を実行して、&lt;a href=&#34;http://localhost:3000/&#34;&gt;http://localhost:3000/&lt;/a&gt; にアクセスして &lt;code&gt;Hello world!&lt;/code&gt; と表示されればおｋ&lt;/p&gt;&#xA;&lt;p&gt;ちなみに &lt;code&gt;--module&lt;/code&gt; というオプションは生成するJSのモジュール形式。&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;commonjs&lt;/code&gt;を指定するとCommonJS形式(Node.jsのrequire)&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;amd&lt;/code&gt;を指定するとRequire.js形式(ブラウザで使う場合)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;となるみたい。&lt;/p&gt;&#xA;&lt;h1 id=&#34;あわせて読みたい&#34;&gt;あわせて読みたい&lt;/h1&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://journal.lampetty.net/entry/setup-typescript-development-environment&#34;&gt;IntelliJ IDEAでTypeScriptの開発環境を作ってみる - おいぬま日報&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;http://www.amazon.co.jp/exec/obidos/ASIN/484433588X/kazzhomeunixo-22/&#34;&gt;&lt;img src=&#34;http://ecx.images-amazon.com/images/I/51pGATfH-gL._SL160_.jpg&#34; alt=&#34;TypeScriptリファレンス Ver.1.0対応&#34; loading=&#34;lazy&#34; title=&#34;TypeScriptリファレンス Ver.1.0対応&#34;&gt;&#xA;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;http://www.amazon.co.jp/exec/obidos/ASIN/484433588X/kazzhomeunixo-22/&#34;&gt;TypeScriptリファレンス Ver.1.0対応&lt;/a&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;作者: わかめまさひろ,井上章,丸山弘詩&lt;/li&gt;&#xA;&lt;li&gt;出版社/メーカー: インプレスジャパン&lt;/li&gt;&#xA;&lt;li&gt;発売日: 2014/05/16&lt;/li&gt;&#xA;&lt;li&gt;メディア: 単行本（ソフトカバー）&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;http://d.hatena.ne.jp/asin/484433588X/kazzhomeunixo-22&#34;&gt;この商品を含むブログ (2件) を見る&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</description>
			</item>
	</channel>
</rss>
