[关闭]
@2890594972 2017-12-25T04:13:50.000000Z 字数 3571 阅读 846

sina云服务器nodejs

云服务器 sina


效果演示地址

http://anli.applinzi.com/

选择服务器配置教程

http://www.saebbs.com/forum.php?mod=viewthread&tid=37798

sae构建node环境

image_1c25ttk4u1b72lv61m33qp51aer30.png-63.8kB

引导构建环境

  1. PS D:\bw\1506\sina\anli> npm init
  2. ...
  3. Press ^C at any time to quit.
  4. package name: (anli)
  5. version: (1.0.0)
  6. description: anli
  7. entry point: (index.js)
  8. test command: start
  9. git repository: (https://git.sinacloud.com/anli)
  10. keywords:
  11. author: daxiang
  12. license: (ISC)
  13. ...
  14. Is this ok? (yes) yes

准备bootstrap模板

image_1c25tloffpulg03rurtmunp13.png-26kB
image_1c25tkgbn1tp118p3dbl8p86f5m.png-1371.5kB

将 html 文本作为页面 send 出去。这里直接使用 node.js 流行框架 Express 帮我们完成这件事

  1. // server.js
  2. var express = require('express')
  3. var app = express()
  4. // 静态 html 页面,需要将当前目录下的所有文件都设置为 static
  5. app.use(express.static(__dirname + '/static/'));
  6. app.get('/', function (req, res) {
  7. console.log('start server');
  8. // sendFile 函数,在有 request 访问时,将当前目录下的 index.html 文件作为 response 返回
  9. res.sendFile(__dirname + '/index.html');
  10. console.log('start success');
  11. })
  12. // 监听 8000 端口
  13. app.listen(process.env.PORT || 8000)

image_1c25tj4ff1sestsi1ldjb1t1qo09.png-57kB

  1. daxiang@daxiang MINGW64 /d/bw/1506/sina/anli (master)
  2. $ git status
  3. On branch master
  4. Your branch is based on 'origin/master', but the upstream is gone.
  5. (use "git branch --unset-upstream" to fixup)
  6. Changes to be committed:
  7. (use "git reset HEAD <file>..." to unstage)
  8. new file: README.md
  9. new file: config.yaml
  10. new file: index.js
  11. new file: package-lock.json
  12. new file: package.json
  13. daxiang@daxiang MINGW64 /d/bw/1506/sina/anli (master)
  14. $ git add .
  15. daxiang@daxiang MINGW64 /d/bw/1506/sina/anli (master)
  16. $ git commit -m 'add hello world'
  17. [master d1530f6] add hello world
  18. 5 files changed, 421 insertions(+)
  19. create mode 100644 README.md
  20. create mode 100644 config.yaml
  21. create mode 100644 index.js
  22. create mode 100644 package-lock.json
  23. create mode 100644 package.json
  24. daxiang@daxiang MINGW64 /d/bw/1506/sina/anli (master)
  25. $ git push origin
  26. Counting objects: 11, done.
  27. Delta compression using up to 8 threads.
  28. Compressing objects: 100% (11/11), done.
  29. Writing objects: 100% (11/11), 5.55 KiB | 1.39 MiB/s, done.
  30. Total 11 (delta 0), reused 0 (delta 0)
  31. remote: 导出 Git 代码中...
  32. remote: 构建程序中...
  33. -----> Node.js app detected
  34. -----> Creating runtime environment
  35. NPM_CONFIG_LOGLEVEL=error
  36. NPM_CONFIG_PRODUCTION=true
  37. NODE_ENV=production
  38. NODE_MODULES_CACHE=true
  39. -----> Installing binaries
  40. engines.node (package.json): 5.9.0
  41. engines.npm (package.json): unspecified (use default)
  42. Downloading and installing node 5.9.0...
  43. Using default npm version: 3.7.3
  44. -----> Restoring cache
  45. Skipping cache restore (new runtime signature)
  46. -----> Building dependencies
  47. Pruning any extraneous modules
  48. Installing node modules (package.json)
  49. nodejs-getting-started@0.0.1 /tmp/build
  50. `-- express@4.16.2
  51. +-- accepts@1.3.4
  52. | +-- mime-types@2.1.17
  53. | | `-- mime-db@1.30.0
  54. | `-- negotiator@0.6.1
  55. +-- array-flatten@1.1.1
  56. +-- body-parser@1.18.2
  57. | +-- bytes@3.0.0
  58. | +-- http-errors@1.6.2
  59. | | +-- inherits@2.0.3
  60. | | `-- setprototypeof@1.0.3
  61. | +-- iconv-lite@0.4.19
  62. | `-- raw-body@2.3.2
  63. +-- content-disposition@0.5.2
  64. +-- content-type@1.0.4
  65. +-- cookie@0.3.1
  66. +-- cookie-signature@1.0.6
  67. +-- debug@2.6.9
  68. | `-- ms@2.0.0
  69. +-- depd@1.1.1
  70. +-- encodeurl@1.0.1
  71. +-- escape-html@1.0.3
  72. +-- etag@1.8.1
  73. +-- finalhandler@1.1.0
  74. | `-- unpipe@1.0.0
  75. +-- fresh@0.5.2
  76. +-- merge-descriptors@1.0.1
  77. +-- methods@1.1.2
  78. +-- on-finished@2.3.0
  79. | `-- ee-first@1.1.1
  80. +-- parseurl@1.3.2
  81. +-- path-to-regexp@0.1.7
  82. +-- proxy-addr@2.0.2
  83. | +-- forwarded@0.1.2
  84. | `-- ipaddr.js@1.5.2
  85. +-- qs@6.5.1
  86. +-- range-parser@1.2.0
  87. +-- safe-buffer@5.1.1
  88. +-- send@0.16.1
  89. | +-- destroy@1.0.4
  90. | `-- mime@1.4.1
  91. +-- serve-static@1.13.1
  92. +-- setprototypeof@1.1.0
  93. +-- statuses@1.3.1
  94. +-- type-is@1.6.15
  95. | `-- media-typer@0.3.0
  96. +-- utils-merge@1.0.1
  97. `-- vary@1.1.2
  98. -----> Caching build
  99. Clearing previous node cache
  100. Saving 2 cacheDirectories (default):
  101. - node_modules
  102. - bower_components (nothing to cache)
  103. - nodegyp_lib (nothing to cache)
  104. -----> Build succeeded!
  105. `-- express@4.16.2
  106. -----> Discovering process types
  107. Default types for -> web
  108. -----> Compiled slug size is 13M
  109. remote: Generating docker image...
  110. remote: Pushing image registry.docker.sae.sina.com.cn/anli:d1530f6 .....
  111. remote: 部署程序中 ..........
  112. To https://git.sinacloud.com/anli
  113. * [new branch] master -> master
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注