serving javascript files in handlebars view engine with express js
Iam a beginner.I wrote a very simple node js to know ,how to work with handlebars .I added javascript animation to home and that animation doesn't works. can any one give simple example on how to work with js file with handlebars .
Hi,
I am not sure if your query is directly related to Express. Please can you post some relevant code so I can take a look what's going on?
Could you also explain in a bit more detail what you're trying to achieve as your title and description of this issue don't seem to match up.
Thanks
Hi @reeceaw here is the link https://hastebin.com/oxohaduwoq.xml The problem is why that simple animation is not working,when I click the button. Thanks
I'm not seeing anywhere you're actually loading the anime.js file. Can you point to where that is? Perhaps that is the issue, that you forgot a <script> tag to load that file?
sorry!! I pasted wrong this the correct link,Thanks.. https://hastebin.com/oxohaduwoq.xml Please verify this code once more .
Thanks! So the issue you're seeing is that the Node.js variable __dirname does not end with a directory separator, so when you concat the string 'public' it's not the directory in your project. You should use path.join instead:
var express=require('express');
var exphbs=require('express-handlebars')
var path = require('path');
var app=express();
app.engine('handlebars',exphbs({defaultLayout:'main'}));
app.use(express.static(path.join(__dirname, 'public')));
app.set('view engine','handlebars')
app.get('/',function(req,res){
res.render('index');
});
app.listen(3000);
I did it now, but it is not working.
Yea, I saw that too, but looks like issues in your JS, not related to Express.
Ok ,Sir if possible will you provide me a source code to know , how to link js to handlebars in express.
I'm not sure what you mean. After the change I provided above, the anime.js file loads and clicking on the button calls your myMove function. Is that what you mean by "linking"?
Yea.
Ok, so that's what the change I provided above does.