# 微信小程序投票node **Repository Path**: carpONE_admin/applet-voting-node ## Basic Information - **Project Name**: 微信小程序投票node - **Description**: 服务端代码 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2021-11-20 - **Last Updated**: 2023-03-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## multer 文档学习 [multer](https://www.baidu.com/link?url=SXkEsiMcpfqhM3IdT5ZZ9sBfuM2FHvJuP-CaQE6exRqZ_gpkzF0t2t5DHsItXq3Ii67f5AfguGkdwSdhJcWt3fF5Glr0wEobtB9e_Xb04KK&wd=&eqid=b1a94bb50005b4870000000661926a8c) ## Express(本地服务器)学习文档 [Express](https://www.expressjs.com.cn/starter/installing.html) ### index1.js中要安装: 1. npm install mockjs --save 2. npm install express --save 3. npm install body-parser --save ### 运行 ```bash node vote.js ``` ## 腾讯云托管node.js指南 [腾讯官方教程](https://cloud.tencent.com/document/product/1243/49237) ### 步骤1:编写基础应用 1. 创建名为 helloworld 的新目录,并转到此目录中: ```bash mkdir helloworld cd helloworld ``` 2. 创建一个包含以下内容的 package.json 文件: ```json { "name": "helloworld", "description": "Simple hello world sample in Node", "version": "1.0.0", "main": "index.js", "scripts": { "start": "node index.js" }, "author": "Tencent CloudBase", "license": "Apache-2.0", "dependencies": { "express": "^4.17.1" } } ``` 3. 在同一目录中,创建一个 index.js 文件,并将以下代码行复制到其中: ```js const express = require("express"); const app = express(); app.get("/", (req, res) => { res.send(`Hello World!`); }); const port = 8080; app.listen(port, () => { console.log(`helloworld: listening on port ${port}`); }); ``` > 说明 > 此代码会创建一个基本的 Web 服务器,侦听 8080 端口。 ### 步骤2:将应用容器化 1. 在项目根目录下,创建一个名为 Dockerfile 的文件,内容如下: ```dockerfile # 使用官方 Node.js 12 轻量级镜像. https://hub.docker.com/_/node FROM node:12-slim # 定义工作目录 WORKDIR /usr/src/app # 将依赖定义文件拷贝到工作目录下 COPY package*.json ./ # 以 production 形式安装依赖 RUN npm install --only=production # 将本地代码复制到工作目录内 COPY . ./ # 启动服务 CMD [ "node", "index.js" ] ``` 2. 添加一个 `.dockerignore` 文件,以从容器映像中排除文件: ```dockerfile Dockerfile .dockerignore node_modules npm-debug.log ``` ### 步骤3(可选):本地构建镜像 1. 如果您本地已经安装了 Docker,可以运行以下命令,在本地构建 Docker 镜像: ```bash docker build -t helloworld ``` 2. 构建成功后,运行 docker images,可以看到构建出的镜像,随后您可以将此镜像上传至您的镜像仓库。 ```bash REPOSITORY TAG IMAGE ID CREATED SIZE helloworld latest 1c8dfb88c823 8 seconds ago 146MB ``` ### 步骤4:部署到 CloudBase 云托管 详情请参见 [部署服务](https://cloud.tencent.com/document/product/1243/46127) 与 [版本配置说明](https://cloud.tencent.com/document/product/1243/49177)。