Closed estvmachine closed 9 years ago
There is require('qs')
in a function called parser
in file MEAN\config\express.js
. Can you find it and post that piece of code here?
Here is the config/express.js, i use bodyParser and cookieParser but not 'parser' alone.
'use strict';
/**
* Module dependencies.
*/
var fs = require('fs'),
http = require('http'),
https = require('https'),
express = require('express'),
morgan = require('morgan'),
bodyParser = require('body-parser'),
compress = require('compression'),
methodOverride = require('method-override'),
cookieParser = require('cookie-parser'),
flash = require('connect-flash'),
config = require('./config'),
consolidate = require('consolidate'),
path = require('path');
//var scribe= require('./log.js');
module.exports = function(db) {
// Initialize express app
var app = express();
// Globbing model files
//config.getGlobbedFiles('./app/models/**/*.js').forEach(function(modelPath) {
// require(path.resolve(modelPath));
//});
// Setting application local variables
app.locals.title = config.app.title;
app.locals.description = config.app.description;
app.locals.keywords = config.app.keywords;
app.locals.facebookAppId = config.facebook.clientID;
app.locals.jsFiles = config.getJavaScriptAssets();
app.locals.cssFiles = config.getCSSAssets();
// Passing the request url to environment locals
app.use(function(req, res, next) {
res.locals.url = req.protocol + '://' + req.headers.host + req.url;
next();
});
// Should be placed before express.static
app.use(compress({
filter: function(req, res) {
return (/json|text|javascript|css/).test(res.getHeader('Content-Type'));
},
level: 9
}));
// Showing stack errors
app.set('showStackError', true);
// Set swig as the template engine
app.engine('server.view.html', consolidate[config.templateEngine]);
// Set views path and view engine
app.set('view engine', 'server.view.html');
app.set('views', './app/views');
// Environment dependent middleware
if (process.env.NODE_ENV === 'development') {
// Enable logger (morgan)
app.use(morgan('dev'));
// Disable views cache
app.set('view cache', false);
} else if (process.env.NODE_ENV === 'production') {
app.locals.cache = 'memory';
}
// Request body parsing middleware should be above methodOverride
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(methodOverride());
// CookieParser should be above session
app.use(cookieParser());
// connect flash for flash messages
app.use(flash());
// Setting the app router and static folder
app.use(express.static(path.resolve('./public')));
// Globbing routing files
//config.getGlobbedFiles('./app/routes/**/*.js').forEach(function(routePath) {
// console.log(routePath);
// require(path.resolve(routePath))(app);
//});
require('../app/routes/compras.server.routes.js')(app);
require('../app/routes/core.server.routes.js')(app);
require('../app/routes/ventas.server.routes.js')(app);
// Assume 'not found' in the error msgs is a 404. this is somewhat silly, but valid, you can do whatever you like, set properties, use instanceof etc.
app.use(function(err, req, res, next) {
// If the error object doesn't exists
if (!err) return next();
// Log it
console.error(err.stack);
// Error page
res.status(500).render('500', {
error: err.stack
});
});
// Assume 404 since no middleware responded
app.use(function(req, res) {
res.status(404).render('404', {
url: req.originalUrl,
error: 'Not Found'
});
});
if (process.env.NODE_ENV === 'secure') {
// Log SSL usage
console.log('Securely using https protocol');
// Load SSL key and certificate
var privateKey = fs.readFileSync('./config/sslcerts/key.pem', 'utf8');
var certificate = fs.readFileSync('./config/sslcerts/cert.pem', 'utf8');
// Create HTTPS Server
var httpsServer = https.createServer({
key: privateKey,
cert: certificate
}, app);
// Return HTTPS server instance
return httpsServer;
}
// Return Express server instance
return app;
};
I know it's not a final solution , but how i could do, for example , an executable version which include only the app / config / folders and folders of my code , but without the node_modules dependencies. In this way , at least I protect my own code , and is a solution that is useful to me.
For this particular error or other , perhaps excluding the module 'express ' in the executable , but keeping the raw reference to ' node_modules/express ' can work? .
Give me time to dig into parsers you use.
Meanwhile, it is a good idea to remove node_modules
from compiled package. You can try to chage require('express')
to require('express', 'dont-enclose')
. So that enclose compiler will not include that express
dependency. You should add dont-enclose
to all your require
calls, that go into node_modules
. After you finish, you get executable, that requires node_modules
directory nearby.
Thank you for responding so fast! , it works if I use ' dont- enclose ' with node_modules . I think I'll including module a module to check for errors and problems , and inform you . Apparently there are indeed problems with 'body -parser ', ' qs ' and 'express ' for the moment, so please go ahead with your good work! .
I try with all my dependencies. And i enclosed them all, less the qs which is a sub-dependency in express, it seems that doesnt enclosed it
Actually i can enclose 'express' but i have to add 'qs' in node_modules and keep the folder with the executable. We almost done, but its better like the beginning.
node_modules Now:
node_modules Before:
I can package, but when i share that package doesnt work in others PCs.
So i compile my original code with -info options and i got the next information. I think i got problems with these packages, can you check them?. I have to add the 'qs' to node_modules to this works (see the the comment before this).
-Express -Body-parser -Compression
Sorry, i was busy porting to ARM. I will try to fix your issue tomorrow.
I suppose its complicated to resolve :S, i really want to advance with this issue. Tell me what i can do for helping.
I made more tests but this much more simple:
1) Just using Express
node_modules= {"express": "~4.10.1", }
var app= require('express')(),
config={ 'port':8080};
app.listen(config.port);
console.log('APP start in the port ' + config.port);
I cant enclosed it a less than i add 'swig' in node_modules before.
2) Using express + bodyparser.
node_modules= {"express": "~4.10.1", "swig": "~1.4.1", "body-parser": "~1.9.0"}
var app= require('express')(),
bodyParser = require('body-parser'),
config={ 'port':8080};
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.listen(config.port);
console.log('APP start in the port ' + config.port);
I can enclosed it, but when i use the package give this error.
So i add 'qs' version 2.3.3 and i can enclose it and run the executable :
node_modules= {"express": "~4.10.1", "swig": "~1.4.1", "body-parser": "~1.9.0", "qs": "2.3.3"}
3) Using express+body-parser+compression All OK, but before i got errors with compression
4) Trying with my others dependencies...
Please try again with 0.2.24. I hope qs
bug is fixed
Its look like works, i try with my simple example. Tomorrow i try with my project. Thanks for work for me xd
Reopen the issue if something happens. Closing now.
Ok thanks, for the moment works but i dont have time for testing in my project. I try with the mini projects for testing and worked at least. So thank you for your hard work.
Hi, i got this error. When i compile i dont have any warning or error, but when i execute the final executable obtain an error for 'express'. Can you check it?.
Or maybe is a different error?. My project is based in MEAN.JS (http://meanjs.org/), but i removed the mongodb part and put a mssql-tedious connection (https://bitbucket.org/randomerp/random-stack/overview). In config/ folder i have to edit explicit 'require' . Too in express/lib/view.js and consolidate (edit_node_modules folder)