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)