0

Is it possible to run angular2 with node js without the given code in nodejs? What if i don't want to use dist folder in nodejs?

app.use('/', express.static('dist'));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
2
  • The dist folder is typescript compiled to javascript as browser's don't understand typescript. Also can you please state the reason for removing the above nodejs code Commented Jun 25, 2017 at 8:17
  • @Dhyey because i have to run ng build everytime i make changes and i'm not able to tun through ng serve Commented Jun 25, 2017 at 8:40

2 Answers 2

0

IMO, dist is basically the compiled angular code, You will still need the angular code somewhere to be served by the node server. From the express server's point of view, it doesn't matter whether its a compiled code (dist) or the uncompiled one.

Note: By compiling I mean build tasks which are performed over the Front End Code, Tasks like minification, uglifications, cdn'ing and many more.

Sign up to request clarification or add additional context in comments.

10 Comments

but @shivam, i need to run ng build again and when if i make a single comma change. Is there any way to run changes without ng build?
Unfortunately no, Since you are using typescript (guessing from the use of ng2). You will have to trigger the build, to compile it down to js
Yes, because ngserve does not save it to disk.. as I read from the documentation github.com/angular/angular-cli/wiki/serve
i have a last doubt, if i upload my complete folder to server so i'll call everything from dist folder. So what if i make some changes and again want to update my server code
Yes you will have to update the server code. There are couple of ways to do it. 1. Creating the new dist file locally and pushing it over to your server as a tarball. This approach has lots of limitations, but is good if its something not changing very regularly. 2. You can set up a deployment pipeline (or CI pipeline) with Jenkins and pushing the not compiled code to github or any other web based VCS. With Jenkins pulling from github and compiling the code, creating the dist. And hence automating the flow
|
0

The main problem of the asker is that he/she does not want to waste precious time calling ng build every time a change is made.

The solution is to use ng build --watch, which builds the files and saves them in the "dist" directory immediately, and every time you change any file, the "dist" directory is updated at once.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.