简体   繁体   中英

How to Integrate angular 4 or higher with express

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::

  • How to integrate express and angular
  • how to use mongoose in it.
  • And crud example for mean app development.
  1. 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);
  2. 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.

  3. This website gives a nice CRUD Example and also goes into Mongoose as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM