DEV Community

Bhautik
Bhautik

Posted on

Deploy your ExpressJS app to zeit Now

πŸ™„ What is Zeit?

ZEIT is the easiest way to deploy websites. Host your web projects with zero configuration, automatic SSL, and global CDN. You can visit their website https://zeit.co/ and explore more things.

In this article, we are going to deploy out expressjs web app to β–² zeit now before we deep dive you have installed Node.js 10 LTS on your machine and zeit account.

Next install now globally on your machine using npm or yarn

$ npm i -g now
Enter fullscreen mode Exit fullscreen mode

After installation configure your account

$ now login
Enter fullscreen mode Exit fullscreen mode

Clone my repository

$ https://github.com/BhautikChudasama/Node-with-zeit.git
Enter fullscreen mode Exit fullscreen mode

In this repository, I created the template of expressjs web app and you can also replace your code in index.js

Here is source code of index.js that sends the response Hello from zeit whenever / and for other wildcards, such /any, /aa, /xyz that sends wild card in response

Next we bind our app to 5000 port.

const express = require("express");
const app = express();

app.get("/", (req, res) => {
    res.send("Hello from zeit");
});
app.get("**", (req, res) => {
    res.send("wild card");
});

app.listen(5000, () => {
    console.log("App is listening on port 5000");
});
Enter fullscreen mode Exit fullscreen mode

Open your terminal and fire

$ now
Enter fullscreen mode Exit fullscreen mode

that asks some basic questions

$ now
? Set up and deploy β€œF:\zeit-demo”? [Y/n] y
? Which scope do you want to deploy to? Bhautik
? Link to existing project? [y/N] n
? What’s your project’s name? zeit-demo
? In which directory is your code located? zeit-demo/
οΏ½πŸ”—  Linked to ** (created .now and added it to .gitignore)
οΏ½πŸ”  Inspect: URL [Hidden]
βœ…  Production: https://zeit-demo-six.now.sh [copied to clipboard] [42s]
οΏ½πŸ“  Deployed to production. Run `now --prod` to overwrite later (https://zeit.ink/2F).  
οΏ½πŸ’‘  To change the domain or build command, go to URL [Hidden]
Enter fullscreen mode Exit fullscreen mode

✌️ After successful deployment that copied the production URL into the clipboard and now you can explore the app in your browser.

Try open https://zeit-demo-six.now.sh/ that show Hello from zeit and https://zeit-demo-six.now.sh/dev that show wild card in the response.

Thank you for reading my first article in dev.to and you can follow me on twitter also @bhautiktweets 😊

Top comments (0)