[Now] Deploy a Node project with Zeit’s Now

发布时间:2017-4-29 5:57:02 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"[Now] Deploy a Node project with Zeit’s Now ",主要涉及到[Now] Deploy a Node project with Zeit’s Now 方面的内容,对于[Now] Deploy a Node project with Zeit’s Now 感兴趣的同学可以参考一下。

Use Zeit’s now to deploy a node application from your local machine to a remote cloud service in moments.

Install:

npm i -g now

Deploy:

now

The url it generates contains two part, the first part is the application name, and the second part is generated according to your application current state (code) and package.json. If you deploy this package against this code, using now, that's the URL that you get. I can show you that that's true by running ZEIT now again. 

If I run Now again, we're not going to see it do npm install and npm run build and npm start, it's actually just going to give us the same URL again. This is using a certain property of immutable data structures.

It's actually saying that this deployed instance is like a pure function of this particular named project with the current state of this code. No matter how many times I deploy the current state, it's always going to return the same deployment instance that I can get to via that URL.

If code changed, when we deploy again, it will genrate a new url, but the old one is still available!.

Now offers a nice little escape hatch here. If we define a script called start, and a script called now start, then when we've run it on Now, it'll ignore start and it'll run now start. The same for build, if we define a now build, echo now build step went here.

  "scripts": {
    "start": "node index.js",  // run this in local
    "now-start": "node index.js", // in server, will run this instead of "start"
    "build": "echo 'BUILD STEP GOES HERE'", // run in local
    "now-build": "echo 'NOW BUILD STEP WENT HERE!'", // run in server
    "test": "echo \"Error: no test specified\" && exit 1"
  },

If you want your dev to run with certain environment variables, for instance, and your prod to run with other ones or something like that, we can dig a little bit more deeper into that in future lessons. There is an escape hatch, and there is a way for you to have Now specific start in build scripts.

上一篇:sublime3 配置node build环境
下一篇:AngularJS 脏检查机制

相关文章

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

最近更新

好贷网好贷款