Git Product home page Git Product logo

matildo-030117's Introduction

Activity 1

Web Dev't Boilerplate Setup using Express

1. Setup Tools

  • Verify nodeJS version. $ node --version
  • Verify npm version. $ npm --version
  • Verify git version. $ git --version
  • Verify sublime version. $ subl --version

2. Setup Web App Framework (Express JS)

  • Create a local repository. $ cd desktop && mkdir lastname-022317 && cd lastname-022317
  • Launch sublime text editor. $ subl .
  • Create package.json. $ npm init -y
  • Install express as dependency. $ npm install express --save
  • Create simple express directory tree. $ mkdir public && mkdir views
+-- lastname-022317
| +-- node_modules
| +-- public
| | +-- css
| | | `-- app.css
| | +-- img
| | | `-- winteriscomming.jpg
| | +-- js
| | | `-- app.js
| +-- views
| | `-- 404.html
| | `-- app.html
| `-- .gitignore
| `-- package.json
| `-- Procfile
| `-- README.md
| `-- server.js

//server.js
//require modules
var express = require('express');
var path = require('path');
//instantiate express
var app = express();
//set port
app.set('port', (process.env.PORT || 5000));
//use static files
app.use(express.static(path.join(__dirname, 'public')));
//express routes
app.get('/', function(req, res){
  res.sendFile(path.join(__dirname, 'views/app.html'));
});
app.get('/about', function(req, res){
  res.sendFile(path.join(__dirname, 'views/about.html'));
});
app.get('*', function(req, res){
  res.status(404).sendFile(path.join(__dirname, 'views/404.html'));
});
//express server listen
var server = app.listen(app.get('port'), function(){
  console.log('Server listening on port ',app.get('port'));
});
<!--index.html-->
<!DOCTYPE html>
<html>
<head>
	<title>My Web App</title>
</head>
<body>
	<h1>Welcome to my web app!</h1>
	<img src="img/winteriscoming.jpg" />

	<br>
	<a href="/">Home</a> |
	<a href="/about">About</a>
</body>
</html>
<!--404.html-->
<!DOCTYPE html>
<html>
<head>
	<title>404 Page</title>
</head>
<body>
	<h1>Error 404: Page cannot be found!</h1>
	<p>Click <a href="/">here</a> to return to main page</p>
</body>
</html>
  • Download images here

3. Upload files to remote repository (Github)

  • Create new github remote repository
  • Open .gitignore file and write node_modules inside.
  • $ git init
  • $ git config user.email "[email protected]"
  • $ git config user.name "yourgithubname"
  • $ git status
  • $ git add .
  • $ git commit -m "my first commit"
  • $ git remote add origin https://github.com/yourgithubusername/yourgithubrepo.git
  • $ git push -u origin master
  • Open your web app at http://localhost:5000 $ node server.js

4. Deploy to heroku

  • $ heroku login
  • $ heroku create lastname-022217
  • $ git status
  • $ git add .
  • $ git commit -m "deploy to heroku"
  • $ git push -u heroku master
  • $ heroku open

matildo-030117's People

Contributors

hyperac1d avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.