简体   繁体   中英

Serving static files with Node.js and AngularJS

I have a very very simple node server, which has one task : serve an HTML file corresponding to the entry point of my AngularJS app.

But I have a problem : I have no cache for static resources, as JS or CSS files. How could I achieve it ? Is it a node or angular problem ?

AngularJS is a client-side framework, and has little to do with the serving of files. Can you not just use Express like this:

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

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

app.listen(process.env.PORT || 3000);

As a side note, it may be more useful to serve static files with something like Nginx.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM