Ad Code

Responsive Advertisement

Create nodejs sample App and deployee on heroku with github

First create nodejs sample APP with ejs

Folder Structure

├── package.json
├── package-lock.json
├── public
│   └── css
│   └── style.css
├── README.md
├── server.js
└── views
└── index.ejs

server.js

    
    var express = require('express');
	var app = express();
	// set the port of our application
    // process.env.PORT lets the port be set by Heroku
    var port = process.env.PORT || 8080;

	// set the view engine to ejs
    app.set('view engine', 'ejs');

	// make express look in the public directory for assets (css/js/img)
    app.use(express.static(__dirname + '/public'));

	// set the home page route
    app.get('/', function(req, res) {
		// ejs render automatically looks in the views folder
        res.render('index');
    });

	app.listen(port, function() {
    	console.log('Our app is running on http://localhost:' + port);
    });
   
   

views/index.html

    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Node Sample App</title>
        <!-- CSS -->
        <!-- load bootstrap and our own personal stylesheet -->
        <link href="//maxcdn.bootstrapcdn.com/bootswatch/3.2.0/superhero/bootstrap.min.css" rel="stylesheet">
        <link rel="stylesheet" href="css/style.css">
    </head>
    <body>
      <div class="container">
          <div class="jumbotron">
              <h1>This Is Heroku App</h1<
              <p><a href="https://ylparth.blogspot.com" class="btn btn-primary btn-lg">read more blogs</a></p>
          </div>
      </div>
    </body>
    </html>
   
   

public/style.css

    
    body    { padding-top:50px; }
	.container .jumbotron    { border-radius:40px; }
   
   

package.json

    
    	{
          "name": "heroku-node",
          "description": "Our sample Node to Heroku app",
          "main": "server.js",
          "scripts": {
            "start": "node server.js"
          },
          "dependencies": {
            "ejs": "~1.0.0",
            "express": "^4.17.1"
          }
        }
   
   

README.md

    
    	# reading-list1
   
   

push your code in existing git repository 'repo1' from the command line

$ git clone
$ npm install
- check your app is running fine
$ npm start
$ git remote add origin
$ git commit -am "added app files"
$ git push -u origin master

we require heroku account

$ heroku login
- create application on heroku
$ heroku create myapp1
$ git push heroku master
$ heroku open

simple setup for connect github with heroku

- goto heroku site > login
- click your app name - myapp1
- in this myapp1 window click connect with github
- enter git credential and login
- enter repository name like - myapp1
- select auto deployee
- select branch like - master (selected branch code lode on heroku app live)
- click deployee
check more

Post a Comment

0 Comments

Close Menu