I started today with NodeJS, ExpressJS, Android, to create a little Webapplication. And I faced a problem an it holds me the whole day!
ENV:
Server: NodeJS, ExpressJS
Client: HTML,Angular, CSS
I try to load the CSS and the JavaScript file from the node_modules folder. But it doesn't work. It works just with the online sources
works
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../public/javascript/test.js"></script>
doesn't work
<script type="text/javascript" src="../public/javascript/test.js"></script>
The server write all the time a 404 Error
I've tried with absolut and relativ path. I've tried also with serveral sugesstions from other stackoverflow posts. without a result.
The Servercode was created by Eclipse IDE with 'Express JS Project'
app.js
var express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, http = require('http')
, path = require('path')
,pageX = require('./routes/pageX');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', routes.index);
app.get('/pageX', function(req,res){
console.log("TEST - PageX");
res.send(pageX.pageX(req, res));
});
app.get('/users', user.list);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
Michael

http.createServer(app).listen(...)withapp.listen(port, function() { console.log('Listening to port: ' + port); });'use strict'; var express = require('express'); var app = express(); var config = require('./config'); app.use(function (req, res, next) { console.log('%s %s', req.method, req.url); next(); }); app.use('/uploads', express.static(__dirname + '/uploads')); app.listen(config.port, function(){ console.log('Listening to port ' + config.port); });