Coder Social home page Coder Social logo

proexpressjs's Introduction

proexpressjs's People

Contributors

azat-co avatar pedroparra 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

proexpressjs's Issues

Code correction -- P92

Chapter 6 - Parameters and Routing, P92
On the second block of code:

app.get('/admin/:username', function(request, response, next) {
  //... Same thing, req.user is avaialble
  return res.render(user);  // -> should be: return res.render(req.user);
});

Another note is that most times you receive request and response as arguments and use them with the short version req and res.

How to use domain in node.js with expressjs

Hi,

I am new to node.js and am using express framework in nodejs. I am accessing data through rest API using node-rest-client module. If API response getting delayed, then server getting disconnected and am restarting the server everytime. Also, how log the exception errors in custom log path. Below is my app.js code, Please check whether i am in right direction,

/**

  • Module dependencies.
    */

var express = require('express')
, util = require('util')
, logger = require('morgan')
, fs = require('fs')
, url = require('url')
, session = require('express-session')
, bodyParser = require("body-parser")
, cookieParser = require("cookie-parser")
, favicon = require('serve-favicon')
, errorHandler = require('errorhandler')
, flash = require('connect-flash')
, methodOverride = require('method-override');

var http = require('http');
var path = require('path');
var Client = require('node-rest-client').Client;
var client = new Client();

var moment = require('moment');
var md5 = require('MD5');

global.moment = moment;
global.client = client;
global.md5 = md5;

// Create a write stream (in append mode)
var accessLogStream = fs.createWriteStream(__dirname + '/access.log', {flags: 'a'})
var app = express();

// All environments
app.set('port', process.env.PORT || 2000);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(favicon(__dirname + '/public/images/favicon.ico'));
app.use(logger("combined", {stream: accessLogStream,skip: function (req, res) { return res.statusCode < 400 }}));
app.use(bodyParser.urlencoded({
extended: true,
limit: '15mb'
}));
app.use(bodyParser.json({limit: '15mb'}));
app.use(methodOverride());
app.use(cookieParser('secret'));
app.use(session({secret: 'ssshhhhh',resave: true,saveUninitialized: true}));
app.use(flash()); // To display flash message(success or failure)
app.use(express.static(path.join(__dirname, 'public')));
// Development only
if ('development' == app.get('env')) {
app.use(errorHandler({ dumpExceptions: true, showStack: true }));
}

app.use(function(err, req, res, next) {
console.error(err.stack);
res.status(500).send('Something broke!');
});

// Common middleware to execute before every request - starts here
app.use(function(req, res, next) {
res.locals.session_values = req.session;
res.locals.success_messages = req.flash('success_messages');
res.locals.error_messages = req.flash('error_messages');
next();
});
// Common middleware to execute before every request - ends here

require('./routes/routed')(app); // File contains all request url declaration.

http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});

Also, logger is storing only http get path not errors.

Please guide me.. Waiting for all valuable reply..

Thanks,
Premkumar M

page 103

app.get('*', function(request, response){
  resquest.end('Hello World');
});

Chapter 4 " server-index "

package.json
"express": "^4.13.4",
"serve-index": "^1.7.3",

var serveIndex = require('serve-index');

app.use('/shared', serveIndex(
path.join('public'), { 'icons': true }
)); // web interface with the folder name (shared), Working

app.use(express.static('public')); //Open the file displaying the message, not working ??

Typo -- P73

Chapter 4 - Working with Middleware, P73
"Summary" section, L8 reads:
"Chapter 4 is a deep dive..."
and should be:
"Chapter 5 is a deep dive..."

Typo -- P7

In page 7, second Tip, line 5.
"...when you need to use some receipe for your project..." --> recipe

ch7 cookies example is not working

  1. cd ch7
  2. run npm start in the ch7 dir
  3. view http://localhost:3000/cookies in browser, it will display
    <!DOCTYPE html><html><head><title></title><link rel="stylesheet" href="/stylesheets/style.css"></head><body><h1>Invalid status code: 0</h1><h2></h2><pre>RangeError: Invalid status code: 0 at ServerResponse.writeHead (_http_server.js:192:11) at ServerResponse._implicitHeader (_http_server.js:157:8) at ServerResponse.OutgoingMessage.end (_http_outgoing.js:573:10) at ServerResponse.send (/Users/helihua/SourceCode/pro-express.js/proexpressjs/ch7/node_modules/express/lib/response.js:191:8) at ServerResponse.json (/Users/helihua/SourceCode/pro-express.js/proexpressjs/ch7/node_modules/express/lib/response.js:235:15) at ServerResponse.send (/Users/helihua/SourceCode/pro-express.js/proexpressjs/ch7/node_modules/express/lib/response.js:134:21) at /Users/helihua/SourceCode/pro-express.js/proexpressjs/ch7/app.js:47:19 at Layer.handle [as handle_request] (/Users/helihua/SourceCode/pro-express.js/proexpressjs/ch7/node_modules/express/lib/router/layer.js:76:5) at next (/Users/helihua/SourceCode/pro-express.js/proexpressjs/ch7/node_modules/express/lib/router/route.js:100:13) at Route.dispatch (/Users/helihua/SourceCode/pro-express.js/proexpressjs/ch7/node_modules/express/lib/router/route.js:81:3)</pre></body></html>

Chapter 3 jsonp

I was working on the example in chapter 3.
I noticed that in your figures you get the response:

/**/ typeof updateView === 'function' && updateView({
"name": "Name",
"publisher": "foo,
"keywords": "foo bar"
});

I was pulling my hair out trying to get that to show up on my DOM. Then I realized that my browser(Windows 10 edge) is downloading a file names jsonp.js with the above response written in it.
(LOL there were 15 by time I found out).

I tried in chrome and then wrote to the DOM like in your figures.

I am still reading the book and working my way through it but could this cause an issue if I or a potential user is using the edge browser and using jsonp?

hi, 1 error in chapter 1

hello.js file

    //the origin code
    app.get('*', function(request, response){
        resquest.end('Hello World');
    });

the above code is not executed. it should correct

    //the origin code
    app.get('*', function(request, response){
        response.end('Hello World');
    });

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.