2
I’m having some questions and problems trying to create a server with nodejs.
The point is I have an application developed with Angularjs very simple and want to do another in nodejs which basically carries the Angularjs.
I created a little server using this code:
var http = require('http'),
fs = require('fs');
fs.readFile('./angular-js-web-form/index.html', function (err, html) {
if (err) {
throw err;
}
http.createServer(function(request, response) {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(html);
response.end();
}).listen(8000);
});
What it does is create a local server by reading the file index.html
, this which is the index
of the application in Angularjs:
Apparently it works, but it can’t import all the Tyles, all the js external, functions and etc.
I know there are servers for that, like Grunt, but wanted to avoid them. I want my angular application to run only with a simple server like this one above.
Does anyone have any idea how to help? Suggestion?
Already I leave my thanks.
EDITION:
I ended up finding this link that is more or less what I need: https://thinkster.io/mean-stack-tutorial/
only that it still uses a module that is the Express, only possible using it? There is no way to create local applications just by importing the index
and the index
doing the import of the rest?
Friend, thank you for your attention, however, the result is still the same
– Paulo Gustavo
Weird. I’m running this code here on the local machine and the server works perfectly: loads JS, CSS, Images and etc. @Paulogustavo
– Denison Luz
What I did was copy this code and put it into a JS file and run it with the Node readHtml.js command. Was it the structure of my project that was wrong? That nodejs file is in the /home/paulo folder. s/test and the application is inside /home/paulo. s/test/app. I changed the code there to get the . /app/index.html.
– Paulo Gustavo
@Paulogustavo Following the structure that Oce spoke above, after you run the command `Node readHtml.js' inside the folder " /home/paulo. s/test" Voce must access the url: "http://127.0.0.1:8000/app". Thus the file "app/index.html" must load its application.
– Denison Luz
Friend, really, the mistake was my own. With that last comment that touched me fafauh. Thank you very much!
– Paulo Gustavo