H_C H_C - 4 months ago 23
Node.js Question

Not loading custom scripts from public folder Express (generator)

I am a newbie to node and express and I am really stuck right now. I want to load a custom script.js form the public folder but it doesnt seem to load. Nothing in the network tab, no errors in the console. When I to go the url: localhost:3000/javascripts/script.js, I am seeing the code. I tried every answer given on SO, but nothing seems to work. Using the express generator. What am I doing wrong here.

See code:

var express = require('express');
var path = require('path');

var index = require('./routes/index');
var users = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(express.static(path.join(__dirname, 'public')));

app.use('/', index);
app.use('/users', users);

index.ejs file

<!-- include head -->
<% include partials/head.ejs %>

<% include partials/header.ejs %>

<% include partials/footer.ejs %>

<script scr="/javascripts/script.js"></script>

index.js file:

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });

module.exports = router;

<script scr="/javascripts/script.js"></script>

should be

<script src="/javascripts/script.js"></script>