1

Is it possible to serve angular.js by using only http module from node, without any other frameworks? Will I have all the functionality that is needed for a simple web app?

This is what I've tried:

http.createServer(function(req, res){
    fs.readFile('./src/index.html', function(err, f1){
        res.writeHead(200, {'Content-Type': 'text/html'})
        res.write(f1)
        fs.readFile('./src/angular.min.js', function(err, f2){
            res.writeHead(200, {'Content-Type': 'application/javascript'})
            res.write(f2)
            res.end()
        })
    })
}).listen(6666)
My intent was to load javascript file that my html document depend on. Even though I'm able to see in DevTools under network tab that GET was made succesfuly to these files, they don't seem to interact as if I would run index.html from file explorer. If angular.min.js was successfully loaded scope variables wouldn't look like "{{ data }}", they would have real value without braces.

Is there some step that I have missed, or something I need to read about to understand how files are linked up?

adict
  • 41
  • 10
  • 1
    What url do you expect angular.min.js to be available at? You need to serve it only for specific url. It doesn't make sense if your webserver will respond with it on every url - you're already trying to do this for index.html, aren't you? – Estus Flask Mar 12 '19 at 14:04
  • Yes estus, I would like angular.min.js to be served for index.html, so that this page can have the functionality. Yeya, thanks for the link, i was searching for this topic for a long time. – adict Mar 12 '19 at 14:43

1 Answers1

0

You just need a static server. It's not have anything with angular.

you can use a simple package like http-server or write the code by yourself like this answer

yeya
  • 1,968
  • 1
  • 21
  • 31