Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tokunami/11203457 to your computer and use it in GitHub Desktop.
Save tokunami/11203457 to your computer and use it in GitHub Desktop.
プロジェクト作成(プロジェクト名 hello-world)
$ mkdir hello-world
hello-worldディレクトリへ移動
$ cd hello-world
package.json を作成
$ vi package.json
package.json
{
"name": "hello-world",
"description": "hello world test app",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "3.x"
}
}
npm install を実行 → package.jsonの記述に従って必要なモジュールがインストールされる
$ npm install
ディレクトリの一覧を確認
$ npm ls
アプリを実装(ファイル名  app.js)
$ vi app.js
app.js
var express = require('express');
var app = express();
app.get('/hello.txt', function(req, res){
var body = 'Hello World';
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Content-Length', Buffer.byteLength(body));
res.end(body);
});
app.listen(3000);
console.log('Listening on port 3000');
アプリの起動
$ node app
→ Listening on port 3000と表示された。
ブラウザでhttp://localhost:3000/hello.txt にアクセスすると、画面に「Hello World」が表示された。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment