Giter VIP home page Giter VIP logo

mean1's Introduction

mean1

Code archive for the book Full Stack JavaScript Development with MEAN

This is really a good book (have a look at Sitepoint). However, cutting and pasting code from ebooks is tedious and prone to errors. You can find here some of the listing found in the book - they might have some modifications, though.

mean1's People

Contributors

piffy avatar simonmackie avatar tvance929 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mean1's Issues

Chapter 8 issues

  1. In Listing 9-9 the Models Employee and Team are not Imported. I added
    require('../models/employee');
    require('../models/team');
    to make it work.

  2. After substituting the script as stated, the http://localhost/employees hangs forever.

Chapter 6

I'm having trouble with chapter 6, after the initial setup of the server within index.js I attempt to go to 127.0.0.1:1337/ within my browser and get the following error in my terminal;

TypeError: Cannot read property 'toUpperCase' of undefined
at Server. (/Users/LewisEccles/Documents/Git projects/human-resources/index.js:8:26)
at emitTwo (events.js:106:13)
at Server.emit (events.js:191:7)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:543:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:105:23)

Looking at the error its obvious its on line 8 in my code which is;

req.method = req.method.toUpperCase();

however looking at the index.js file here on github, it is an exact match, I've even copied and pasted it over my code however it still doesn't work.

Due to the error, I get an error in chrome saying that 127.0.0.1 refused to connect.

Does anyone know how I can fix this error, or provide me some guidance on where to look for an answer?

My full index.js is below in case anyone wants to see it there.

Thanks

var http = require('http');

http.createServer(function (res,req) {
  //A parsed url to work with in case there are parameters
  var _url;

  //In case the client uses lower case for methods
  req.method = req.method.toUpperCase();

  console.log(req.method + ' ' + req.url);

  if (req.method !== 'GET') {
    res.writeHead(501, {
      'Content-Type': 'text/plain'
    });

    return res.end(req.method + ' is not implemented by this server');
  }

  if (_url = /^\/employees$/i.exec(req.url)) {
    //return a list of employees

    res.writeHead(200);
    return res.end('employee list');

  } else if (_url = /^\/employees\/(\d+)$/i.exec(req.url)) {

    //find employee by id in the route
    res.writeHead(200);
    return res.end('a single employee');

  } else {

    //try to send the static file
    res.writeHead(200);
    return res.end('static file maybe');
  }

}).listen(1337, '127.0.01');

console.log('Sever Running at http://127.0.0.1:1337/');

Chapter 9 populate_db.js did not link employees to a team

I ran this and when I checked the employees data using mongodb the team attribute was null;

To fix this I needed change 2 functions:

  1. addTeams

if (error) {
console.error('Error: ' + error);
} else {
data.team_id = team1._id;
}

changed to

    if (error) {
        console.error('Error: ' + error);
    } else {
        team1.forEach(function (team1a) {
            data.teams.forEach(function (team) {
                if (team.name === team1a.name) {
                    team.team_id = team1a._id;
                }
            });
        });
    }
  1. updateEmployeeTeams

Employee.update({}, {
team: data.team_id
}, {

changed to

Employee.update({}, {
    team: team.team_id
}, {

Chapter 8 array passed to create function ?

In both insertTeams and insertEmployees :

When the array is passed to create for either Team or Employee, later on, both devops and acct are undefined and pd is an array.

I had to remove the square brackets when create is called for both Team and Employee for later code to work correctly.

Chapter 6: index.js cannot serve static files this way !

You should replace the last lines of index.js

...
 } else {
    // Try to send static files
    res.writeHead(200);
    res.end('static file maybe');
  }

with

...
 } else { 
    staticFile(req.url,res); 
  }

The program as is will continue to respond with 'static file maybe' to every request not intercepted by the preceding routing tests.

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.