Help us understand the problem. What is going on with this article?

nodeで静的ページを動かす最短メモ

More than 1 year has passed since last update.

ちょっとnodeを試してみたいときに使用。

新しいフォルダにnpmの設定ファイルを作る

mkdir new_project
cd new_project
npm init

expressをインストール

expressは簡単なアプリが作れるライブラリ。

npm install express --save

表示するhtmlファイルを用意する

mkdir htdocs
touch htdocs/index.html
touch index.js
index.js
var express = require('express');
var app = express();

app.use(express.static('htdocs'));

var port = 3000;
app.listen(port,function(){
    console.log("Expressサーバーがポート%dで起動しました。モード:%s",port,app.settings.env)
});
index.html
<html>
<head>
    <title>test</title>
</head>
<body>
<h1>テスト</h1>
</body>
</html>

実行

node index.js

下記にブラウザで接続

http://localhost:3000/


使う3つのコマンド

npm init
npm install
npm run

npm installコマンド

個別にインストール

npm install パッケージ名

dependencies内に入ったライブラリはnpm installでインストール

npm install
package.json
{
  "dependencies": { "jquery": "^2.1.3" }
}

参考

フロントエンド開発の3ステップ(npmことはじめ)
http://qiita.com/hashrock/items/15f4a4961183cfbb2658

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした