Giter Site home page Giter Site logo

cs50-expresstemplate's Introduction

CS50xMiami Express Template

Express and Node.js

Table of Contents

Prerequisites

You'll have to run through the prerequisites if you wish to follow along

Node.js and NPM packages

First, you'll need the latest LTS Node.js release installed in order to install these prerequisites.

$ npm install -g express-generator
$ npm install -g nodemon

Git

Setup

Setup

Server Setup

  • cd into your project (should be obvious by now ;))
    • $ cd example.com
    • $ pwd
  • Rather than build an express server from a blank text file, we'll generate a very basic template using express-generator.
    • $ express --ejs
  • Install node modules
    • ```$ npm isntall ``
  • Start your server to see if it works
    • $ nodemon
  • If nodemon doesn't spit out an error, check out localhost:3000 in your browser to double check everything is running fine

Git Setup

Before we can push our code to git, we need to create a ".gitignore" file inside the root of our git repo to prevent git from adding the following OS specific code, logs, etc.

# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

Once the .gitignore file has been both created and committed to the repository, we can start committing the rest of our code without worry.

  • First commit .gitignore
    • $ git add .gitignore
    • $ git commit -m "created .gitignore to filter unwanted nodejs files"
  • Then commit the rest of your code
    • $ git add *
    • $ git commit -m "Express server templated generated"
  • Push your commits to GitHub!
    • $ git push

Express Server Anatomy

The Express.js server we generated follows MVC structure. I'll cover setting up a basic view and transition into creating templates with the controller.

Directory structure:

example.com/
├── app.js
├── bin/
│   └── www
├── node_modules/
│   └── (╯°□°)╯︵ ┻━┻
├── package.json
├── public/
│   ├── images/
│   ├── javascripts/
│   └── stylesheets/
│       └── style.css
├── routes/
│   ├── index.js
│   └── users.js
└── views/
    ├── error.ejs
    └── index.ejs

View

View

Public

Public

Views

Views

Controller

Controller

App.js

App.js

Routes

Routes

NPM

NPM

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

cs50-expresstemplate's People

Watchers

 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.