Reputation: 171
i want to integrate angular 4 or higher than that with my existing express folder.
As i am new to mean stack development i want clean and understandable steps how to integrate angular with express.
Anyone having reference links for the following::
Upvotes: 0
Views: 2305
Reputation: 476
Integrating Angular and Express can be done through a single server.js
file placed in the root directory of your Angular project. Use Angular CLI to ng build --prod
and generate a dist/
folder. You can then link the dist/
folder through the following code in your server.js
file and running node server.js
.
// Define variables
const express = require('express');
const app = express();
// Use the /dist directory
app.use(express.static(__dirname + '/dist'));
// Catch all other invalid routes
app.all('*', function(req,res){
res.status(200).sendFile(__dirname + '/dist/index.html');
});
// Start the server
app.listen(process.env.PORT || 3000);
The Mongoose Docs are very good, but if you need a video, this one: Mean Stack Front to Back: Part 3 is a nice code-along you can work with. The Mongoose part starts about 90 seconds into the video.
This website gives a nice CRUD Example and also goes into Mongoose as well.
Upvotes: 2