Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static files served by node.js on heroku - is it a good idea? [closed]

I have Backbone powered single page app. App consists of couple of files:

index.html
javascripts/app.js
javascripts/vendor.js
stylesheets/app.css
images/ -> image assets

I want to add prerender.io service to my app to make it SEO-friendly. The easiest way of doing this for me is to use express.js hosted on heroku:

var express = require('express');
var app = express();
app.use(require('prerender-node').set('prerenderToken', 'YOUR_TOKEN'));
// ...
app.listen(process.env.PORT || 5000);

But maybe express or actually node are not best for serving static files? Maybe heroku isn't best for serving static files? What will be best solution? What do you recommend?

like image 1000
user606521 Avatar asked Dec 29 '25 17:12

user606521


2 Answers

See this StackOverflow question for serving static files through expressjs: static files with express.js

You should be able to use Heroku's free dyno to handle a good bit of traffic since you're only serving static files.

I would suggest putting all of those files/folder in a "public/" directory and using this code:

var express = require('express'); 
var app = express();
app.use(express.static(__dirname + '/public'));

app.listen(process.env.PORT || 3000);
like image 152
Prerender.io Avatar answered Jan 03 '26 14:01

Prerender.io


You better use CDN for serving static files like Amazon S3.

like image 27
Maxo Avatar answered Jan 03 '26 12:01

Maxo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!