Node.js — Install Express

Image Source
Assuming you have already installed Node.js

First, use terminal to create a directory to hold your application.

mkdir firstapp
cd firstapp

Use the npm init command to create package.json file that contains application’s information.

npm init

And then this command will prompts several questions about application, such as application name, version number…, etc.

For now, you can just press enter to use default value.

Questions about application.

Install Express in your directory and save it in the package.json’s dependencies list.

npm install express --save

Create a file called index.js and add some code below :

var express = require('express');
var app = express();

app.get('/', function (req, res) {
res.send('Hello World');
});

app.listen(3000);

Use npm start command to run your code, than open the link localhost:3000/ in browser.

npm start

Now you can see your first app in the screen!

碎念

最近有點受到大神同事們的影響,加上不知道是不是因為年紀大了有點金魚腦,記憶力越來越糟了orz,所以想要開始寫點文章幫助自己記憶。

但太少寫這種文字的東西了,又不想面對自己無趣的文字所以就乾脆練習寫英文(結果英文句子大部分也都是抄官網的QQ)。

總之雖然很短但終於寫了人生第一篇文章,希望不會同時是最後一篇哈哈哈,下篇文章明年見。