Node & Express Starting Guide

NodeJS + Express 简明指引

安装

Ubuntu

# 安装 node 环境:8.x LTS
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
npm i -g npm # 升级 npm 到最高版本。
npm i express express-generator -g # 全局安装 Express JS 框架及命令行。
express docs --hbs                 # 在目录 docs 下生成使用 express 框架的网站,并指定 handlebars 做页面引擎。
cd docs
npm i                  # 安装 express 框架依赖库。
DEBUG=docs:* npm start # 启动 express 应用,默认 node 应用都跑在 3000 端口。

目录结构

public
routes
views

macOS

brew install node@10 node@12 node@14

If you need to have node@10 first in your PATH run:
  echo 'export PATH="/usr/local/opt/node@10/bin:$PATH"' >> ~/.zshrc

For compilers to find node@10 you may need to set:
  export LDFLAGS="-L/usr/local/opt/node@10/lib"
  export CPPFLAGS="-I/usr/local/opt/node@10/include"

If you need to have node@12 first in your PATH run:
  echo 'export PATH="/usr/local/opt/node@12/bin:$PATH"' >> ~/.zshrc

For compilers to find node@12 you may need to set:
  export LDFLAGS="-L/usr/local/opt/node@12/lib"
  export CPPFLAGS="-I/usr/local/opt/node@12/include"

If you need to have node@14 first in your PATH run:
  echo 'export PATH="/usr/local/opt/node@14/bin:$PATH"' >> ~/.zshrc

For compilers to find node@14 you may need to set:
  export LDFLAGS="-L/usr/local/opt/node@14/lib"
  export CPPFLAGS="-I/usr/local/opt/node@14/include"

常用 node 工具包

sudo npm i -g yo
sudo npm i -g generator-aspnet
Author: njun
njun's picture
Updated: 2021/01/24