-5

How do I use:

https://github.com/gdi2290/angular-starter

With express framework? I can start the webpack dev server fine, but I want to use the plethora of libraries like cookieparser (https://www.npmjs.com/package/cookie-parser).

Though npm start uses webpack-dev-server, and I have no idea what file to use to be able to put in app.use statements and import the cookieparser..

Rolando
  • 58,640
  • 98
  • 266
  • 407
  • 1
    DId not you already ask the same question? https://webcache.googleusercontent.com/search?q=cache:ro6MCP54ZToJ:https://stackoverflow.com/questions/44658831/how-to-add-express-into-angular-starter+&cd=6&hl=fr&ct=clnk&gl=fr – David Feb 20 '18 at 13:05
  • The method outlined in the answer did not work since update... but I have since found a workaround. – Rolando Feb 21 '18 at 00:29

2 Answers2

0

In the version at the time of writing, update webpack.dev.js with the following:

node: {
  global: true,
  crypto: 'empty',
  process: true,
  module: false,
  clearImmediate: false,
  setImmediate: false,
  fs: 'empty',
  net: 'empty'
}

Everything should work as expected after.

Rolando
  • 58,640
  • 98
  • 266
  • 407
0

Just want to jump in and tell you I have an express server that talks to front-end angular server, I build them separate so I dont fill one or the other with redundant libraries and then once im ready I just have the build path for 'dist' point to my server folder like so:

"apps": [
    {
      "root": "src",
      "outDir": "server/dist", //<--- Here, I point to where my server.js, so i can simply build and its ready for production
      "assets": [
        "assets",
        "favicon.ico"
      ],

This is my whole server.js that I launch with node server.js

let express = require('express');
let passport = require('passport');
let session = require('express-session');
const config  = require('./server/auth/config');
let oauth2orize = require('oauth2orize');
const app = express();
const cors = require('cors');
const html = __dirname + '/dist';

app.use(passport.initialize());
app.use(passport.session());

app.use(cors());
app.options('*', cors());
app.use('/api', require('./server/misc/routemanager'));

/**
 * This line tells the server to provide our angular site (after running ng build with it)
 */
app.use(express.static(html));
app.get('*', function(req, res) {
    res.sendFile(html + '/index.html')
});

app.listen(4949, () => {
    console.log(`Node Express server listening on http://localhost:4949`);
});

Now I can build my express backend however I want and talk to it through routes, and still launch the whole thing in one node launch

Cacoon
  • 2,467
  • 6
  • 28
  • 61