上一篇我們理解如何建立一個前端的專案,在繼續之前我也想分享一下如何開啟一個後端的專案,嚴格來說其實是一個全端的專案,這裡會使用到一樣是使用 JS 語言 Node.js 搭配 Express 框架來完成。
NPM (Nodejs Program Management) 是 NodeJS 平台的套件管理工具
Ex:
{
"name": "foodstry-backend",
"version": "1.0.0",
"description": "The backend of foodstry which is the food management tool.",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ci-yang/foodstry-backend.git"
},
"author": "Ci Yang",
"license": "ISC",
"bugs": {
"url": "https://github.com/ci-yang/foodstry-backend/issues"
},
"homepage": "https://github.com/ci-yang/foodstry-backend#readme"
}
** script ** - 可攥寫各種指令,除了預設的 test & start 可直接使用 npm [command] 以外,其餘自訂的指令必須使用 run npm [command] e.g. run npm lint
使用 install 安裝你的套件
npm install [package name]
以下是有利於開發的套件
chalk
debug
morgan
nodemon
the package allow you restart your program automatically
Install by npm install nodemon
use nodemon instead of node to start your program, e.g. nodemon app.js
make the configuration
"nodemonConfig": {
"restartable": "rs",
"ignore": [
"node_modules/**/node_modules"
],
"delay": "2500",
"env": {
"NODE_ENV": "development",
"PORT": 4000
}
}
restartable: "rs" means if you hit "rs", restart the proram
Ignore: set the dir you want to ignore that when you change them, nodemon will do not restart
Delay: to delay 2500 milliseconds
env: Various of env settings whatever you want, e.g. databae location
Add start command "nodemon app.js"
eslint
如此就建立一個全端的 Web 專案,包含了好用的檢查與 debug 工具,可以更佳輔助我們建立一個全端的應用~