Skip to content
techird edited this page Apr 6, 2016 · 2 revisions

Step0. 配置 nginx 以及初始化 Node 源码,使线上可访问

本步骤源代码可以在 workflow/step-0 分支上获取

参照之前项目的 nginx 配置方式,创建 Node 应用在 3000 端口运行。项目的启动代码如下:

// server.js
'use strict';

const express = require("express");

function start(port) {
    const app = express();
    
    // tells the client the server can work.
    app.get("/", (request, response) => {
        response.write("It works!");
        response.end();
    });
    app.listen(port || 3000);
}

start();

本项目每个文件开头都有个 'use strict' 语句,其作用可以参考 Strict Mode - MDN

下面,我们使用 PM2 来运行上面的应用。先使用 npm 安装一下 pm2

npm install pm2 --global

安装完之后,到应用目录上就可以使用 pm2 来启动应用了:

pm2 start server.js --watch

PM2 启动应用

此时访问对应的线上地址(或用 Postman 提交),应该可以看到服务器输出了一句简单的 "It works!"

It Works

下一步:Step1. 支持用户上传图片到云服务器

Clone this wiki locally