Skip to content

Instantly share code, notes, and snippets.

@JStans12
Last active November 16, 2016 22:32
Show Gist options
  • Save JStans12/315003c11e027b0563d71c2b65ae277e to your computer and use it in GitHub Desktop.
Save JStans12/315003c11e027b0563d71c2b65ae277e to your computer and use it in GitHub Desktop.

cd to new directory and:

npm init

setup express:

npm install express --save
touch server.js

inside server.js:

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

app.listen(3000, function() {
  console.log("listening on 3000")
})

use nodemon to auto restart server:

npm install nodemon --save-dev

create shortcut to start server in package.json:

"scripts": {
   "start": "nodemon server.js"
}
npm start

now navigate to http://localhost:3000/ and see:
Cannot GET /

setup ejs template engine:

npm install ejs --save
mkdir views

add to server.js (above app.listen):

app.set('view engine', 'ejs')

test with mocha and chai:

npm install mocha -g
touch package.json
echo {} > package.json
npm install chai --save-dev

test example:

var chai = require('chai')
var expect = chai.expect;
var Greeting = require('../greeting.js');

describe('Hello', function() {
   it('should return 5', function() {
     var greeting = new Greeting();
     expect(greeting.hello()).to.equal('hello');
   });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment