How to use an external js-File in Nodejs, ExpressJS
<p>I started today with NodeJS, ExpressJS, Android, to create a little Webapplication. And I faced a problem an it holds me the whole day!</p>

<p>ENV: </p>

<p>Server: <code>NodeJS</code>, <code>ExpressJS</code></p>

<p>Client: <code>HTML</code>,<code>Angular</code>, <code>CSS</code></p>

<p>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 </p>

<p><strong>works</strong>  </p>

<pre><code>&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"&gt;
  &lt;script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="../public/javascript/test.js"&gt;&lt;/script&gt;
</code></pre>

<p><strong>doesn't work</strong></p>

<pre><code>&lt;script type="text/javascript" src="../public/javascript/test.js"&gt;&lt;/script&gt;
</code></pre>

<p>The server write all the time a 404 Error</p>

<p><a href="https://i.stack.imgur.com/lPNgl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lPNgl.png" alt="enter image description here"></a></p>

<p>I've tried with absolut and relativ path.
I've tried also with serveral sugesstions from other stackoverflow posts. without a result.</p>

<p>The Servercode was created by Eclipse IDE with 'Express JS Project'</p>

<p><strong>app.js</strong></p>

<pre><code>    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'));
});
</code></pre>

<p>Michael</p>