1

Newbie question that is driving me crazy. I am trying to build the ToDo app with the MEAN stack and I can't get the Express server to connect to Angular 2. I believe it has something to do with where I have my index.html view relative to the Angular installation, but I can't figure it out.

0

1 Answer 1

2

Your project folder struction should like below

project/server [Node]

project/server.js is your express server

// Get our API routes
const api = require('./server/routes/api');

const app = express();

// Parsers for POST data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist')));

// Set our api routes
app.use('/api', api);

// Catch all other routes and return the index file
app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'dist/index.html'));
});

project/src/index.html [angular code]

You can build angular code into dist using

ng build

This creates the dist folder with the angular 2 app built files. Now we can serve the app with express.

For run server use

node server.js

which create server

Go through https://scotch.io/tutorials/mean-app-with-angular-2-and-the-angular-cli for more information.

Thanks in advance

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

2 Comments

Thank you so muck Brijal Savaliya
Please feel free to up vote and check anwser as right if you think so..

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.