Coder Social home page Coder Social logo

andrewkeig / advanced-express-application-development Goto Github PK

View Code? Open in Web Editor NEW
59.0 14.0 20.0 245 KB

Source code for book: Advanced Express Web Application Development

Home Page: https://www.packtpub.com/web-development/advanced-express-web-application-development

JavaScript 98.39% CSS 1.61%

advanced-express-application-development's Introduction

Advanced Express Web Application Development

This module contains the source code for the above book. Please look at the readme for each individual chapter for further information.

  • Chapter 1 : Foundations
  • Chapter 2 : Building a Web API
  • Chapter 3 : Templating
  • Chapter 4 : Real-time communication
  • Chapter 5 : Security
  • Chapter 6 : Scaling
  • Chapter 7 : Production

In Detail

Building an Express application that is reliable, robust, maintainable, testable, and can scale beyond a single server requires a bit of extra thought and effort. Express applications that need to survive in a production environment will need to reach out to the Node ecosystem and beyond, for support.

You will start by laying the foundations of your software development journey, as you drive-out features under test. You will move on quickly to expand on your existing knowledge, learning how to create a web API and a consuming client. You will then introduce a real-time element in your application.

Following on from this, you will begin a process of incrementally improving your application and tackle security, SSL support, and security vulnerabilities. Next, the book will take you through the process of scaling and then decoupling your application. Finally, you will take a look at various methods to improve your application's performance and reliability.

What you will learn from this book

  • Develop a feature driven Express web application
  • Build and consume a RESTful web API using client and server side templating
  • Secure and protect Express with passport authentication and SSL via stud
  • Scale Express beyond a single server with Redis and Hipache
  • Decouple Express for improved scalability and maintainability
  • Support real-time application development with Socket.IO
  • Handle failures with a minimum impact to service availability using clusters and domains
  • Understand and cope with Express limitations, including when and where to go for help

Approach

A practical book, guiding the reader through the development of a single page application using a feature-driven approach.

Who this book is written for

If you are an experienced JavaScript developer who wants to build highly scalable, real-world applications using Express, this book is ideal for you. This book is an advanced title and assumes that the reader has some experience with Node.js, JavaScript MVC web development frameworks, and has heard of Express before, or is familiar with it. You should also have a basic understanding of Redis and MongoDB.

advanced-express-application-development's People

Contributors

alsoicode avatar andrewkeig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

advanced-express-application-development's Issues

Discrepancies between the book and the repo

I don't know if here is the right place to report this, but here it goes:

On chapter 2, Feature: List issues, I see that the code here in the repo is very different (and makes a lot more sense, by the way) from the same code from the book, in the method Project.prototype.issues, in the file lib/project/index.js.

In the book, I have:
exports.issues = function (req, res) {
logger.info('Request' + req.url);

ProjectSchema.findOne({_id: req.params.id}, function (error, project) {
  if (error) return res.json(500, 'Internal Server Error');
  if (project == null) return res.json(404, 'Page Not Found'):

  var git = GitHubRepo(project.token, project.user);

  git.issues(project.repositories, function (error, response) {
    if (error) return res.json(500, 'Internal Server Error');
    return res.json(200, response);
  });
});

};

Are you planning correcting that and update the book? I bought the book from Amazon, and I haven't received any sort of update, so I'm not sure if you already corrected that.

grunt coverage is not working with latest devDependencies

Hello,

I'm currently working on chapter 2 of your book.

When i use last version of the devDependencies, the coverage.html page is not working, I do have a blank html page when i run grunt coverage

"devDependencies": {
    "supertest": "~0.8.3",
    "grunt": "~0.4.2",
    "grunt-cafe-mocha": "~0.1.10",
    "grunt-jscoverage": "0.0.3",
    "grunt-env": "~0.4.1",
    "mocha": "~1.17.0"
  }

Do you have a solution to this issue ?

Thanks

Chapter 2 Tests failing with TypeError: Cannot call method 'drop' of undefined

Following the code samples up to page 24, my project.js test file...

var app = require('../app'),
    request = require('supertest'),
    assert = require('assert'),
    mongoose = require('mongoose'),
    login = require('./login');

describe('Vision Project API', function() {
    var id;

    beforeEach(function(done) {
        mongoose.connection.collections['projects'].drop(function(err) {

            var proj = {
                name: "test name",
                user: login.user,
                token: login.token,
                repositories: ["node-plates"]
            };

            mongoose.connection.collections['projects'].insert(proj, function(err, docs) {
                id = docs[0]._id;
                done();
            });
        });
    });

    describe("When creating a new resource /project", function() {
        var project = {
            name: "New Project",
            user: login.user,
            token: login.token,
            repositories: ["12345", "9898"]
        };

        it("should responsd with 201", function(done) {
            request(app).post("/project").send(project).expect("Content-Type", /json/).expect(201).end(function(err, res) {
                var proj = JSON.parse(res.text);
                assert.equal(proj.name, project.name);
                assert.equal(proj.user, login.user);
                assert.equal(proj.token, login.token);
                assert.equal(proj.repositories[0], project.repositories[0]);
                assert.equal(proj.repositories[1], project.repositories[1]);
                assert.equal(res.header['location'], '/project/' + proj._id);
                done();
            });
        });
    });
});

Results in:

1) Vision Project API "before each" hook:
 TypeError: Cannot call method 'drop' of undefined
  at Context.<anonymous> (/home/btaylor/node-projects/vision/test/project.js:11:53)
  at Hook.Runnable.run (/usr/lib/node_modules/mocha/lib/runnable.js:204:15)
  at next (/usr/lib/node_modules/mocha/lib/runner.js:263:10)
  at Object._onImmediate (/usr/lib/node_modules/mocha/lib/runner.js:280:5)
  at processImmediate [as _immediateCallback] (timers.js:330:15)

MongoDB is running, and the "vision" database exists...what am I doing wrong?

Thanks,
Brandon

Chapter 2 tests no change (just Github token updated) 22 passed but 2 tests failed.

22 passing (3s)
2 failing

  1. vision github api when requesting an available resource /project/:id/commits should respond with 200:
    Uncaught TypeError: Cannot convert null to object
    at hasOwnProperty (native)
    at Function._.has (/Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/underscore/underscore.js:995:27)
    at /Users/aozturk/Development/advanced-express-web-application-development/chapter-2/test/github.js:73:20
    at Test.assert (/Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/supertest/lib/test.js:190:3)
    at /Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/supertest/lib/test.js:119:10
    at Test.Request.callback (/Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/supertest/node_modules/superagent/lib/node/index.js:573:30)
    at Test. (/Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/supertest/node_modules/superagent/lib/node/index.js:133:10)
    at Test.EventEmitter.emit (events.js:95:17)
    at IncomingMessage. (/Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/supertest/node_modules/superagent/lib/node/index.js:703:12)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

  2. vision github api when requesting an available resource /project/:id/issues should respond with 200:
    Uncaught TypeError: Cannot convert null to object
    at hasOwnProperty (native)
    at Function._.has (/Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/underscore/underscore.js:995:27)
    at /Users/aozturk/Development/advanced-express-web-application-development/chapter-2/test/github.js:111:20
    at Test.assert (/Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/supertest/lib/test.js:190:3)
    at /Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/supertest/lib/test.js:119:10
    at Test.Request.callback (/Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/supertest/node_modules/superagent/lib/node/index.js:573:30)
    at Test. (/Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/supertest/node_modules/superagent/lib/node/index.js:133:10)
    at Test.EventEmitter.emit (events.js:95:17)
    at IncomingMessage. (/Users/aozturk/Development/advanced-express-web-application-development/chapter-2/node_modules/supertest/node_modules/superagent/lib/node/index.js:703:12)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

Trouble "Authorising App" in Chapter 5 page 93.

First indication, Cucumber tests fail at 'Then I should see my name and logout link'.

Logged in to app and clicked "Authorize Application" button. Returns straight back to home page.

Built chapter 5 code from this repo - same thing.

Without getting bogged down in researching the ins and outs of OAuth, is there any quick fix to get this working?

Many thanks in advance.

Github Commits - Fatal error: Cannot convert null to object

Hello. When running test on completion of the Commits feature ending on page 39, I get the following error:

Fatal error: Cannot convert null to object

I have copy/pasted from source, but I still get the same error. Running tests from the source work, so I'm not sure where I've made a mistake.

I've tried logging out the response, commits, etc, but that's not really getting me anywhere. From what I can tell, the response text for 'project/:id/commits' is coming back as [], but when I log the response or commits variables, I get no output, which means their null.

I can copy the source from the repo over, but I'd really like to know where my mistake is, and would appreciate if you could take a look.

Thank you!

Question not issue

Hello I'm using your book to write my first advanced app so I'm excited. My question is: For the project schema, why do you not set the the 'name' attribute as unique? Instead you check for the existence of 'name' by calling projectSchema.findOne before calling either project.save or project.update. Is there a reason why you do no want this validation check in the model? If there is a better place to ask questions than github I am sorry for not knowing.

update:
The question could also apply to your check in the post and put routes where you use the String module to check for empty 'name' values instead relying on the model's validation
ex. if (S(req.body.name).isEmpty() ) return res.json(400, 'Bad Request');

So what if I added to the model that I want 'name' to not be over 10 chars. Would you continue to check for this in the routes or would you suggest using the mongoose's validation error?

thank you kindly.

cafemocha:test aborted

Hello,

I'm working through Chapter 1, and receiving the following error when running:

$ grunt test

Running "env:test" (env) task

Running "cafemocha:test" (cafemocha) task
Warning: Cannot log to file without filename or stream. Use --force to continue.

Aborted due to warnings.

I have copy/pasted the gruntfile.js from the source code here. What am I doing wrong or missing?

Thanks!

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.