LoginSignup
0
0

More than 5 years have passed since last update.

PowerShellでexpressコマンドを使う

Last updated at Posted at 2015-06-13

概要

Node.js Command Prompt(以下NCP)だと起動時に.batを実行することでexpressコマンドが使えるようになっているんですが、PowerShellだとうまくいかない。PowerShellのほうが使いやすいのでこちらでもできないかと思い、やってみました。とはいえやっていることは環境変数の設定だけなので大したことではありません。

前提

PowerShellからps1ファイルを実行できるように設定してあること
[参考]
http://www.atmarkit.co.jp/ait/articles/0805/16/news139.html
https://technet.microsoft.com/ja-jp/scriptcenter/powershell_owner05.aspx

主な手順

1.Powershellのショートカットを作成

任意の場所にPowerShell.exeへのショートカットを作成し、ショートカットのプロパティを下記のように設定する。
PowerShell起動時にnodejsフォルダ内のnodevars.ps1を実行するように設定しています。
-noexitはスクリプト実行後もPowerShellが終了しないようにしています。

PowerShellのショートカットのオプション
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit &'C:\Program Files\nodejs\nodevars.ps1'

2.ps1スクリプトを作成

このスクリプト内で環境変数を設定します。
作ったスクリプトの場所と、expressのあるAPPDATA/npmを環境変数に設定しています。
このスクリプトを、1.で指定した場所(ここではC:\Program Files\nodejs)にnodevars.ps1という名前で保存します(管理者権限が必要です)。

nodevars.ps1
$scriptPath = $MyInvocation.MyCommand.Path
$scriptPath = Split-Path $scriptPath -Parent 
$env:path = $env:path + ";" + $env:APPDATA + "/npm;" + $scriptPath

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0