Akida
Akida

Reputation: 5

MEAN app, what should I change before release on server?

I based on this tutorial: https://coursetro.com/posts/code/84/Setting-up-an-Angular-4-MEAN-Stack-(Tutorial) and I build my app and it works well, but I have a problem. I wanted to release the application on the server. But im not sure what should I change. Server runs on Debian based os. App on server should work on port 80, and MongoDB should work on default 27017 port. Here is my original and changes files:

Orginal server.js:

1 app.use(bodyParser.json());
2 app.use(bodyParser.urlencoded({ extended: false}));
3 app.use(express.static(path.join(__dirname, 'dist')));
4 app.use('/api', api);
5 app.get('*', (req, res) => {
6   res.sendFile(path.join(__dirname, 'dist/index.html'));
7 });
8 const port = process.env.PORT || '3000';
9 app.set('port', port);
10 const server = http.createServer(app);
11 server.listen(port, () => console.log(`Running on localhost:${port}`));

Before release i change line 8 to

 const port = process.env.PORT || '80';

and I'm not sure but should I change line 3 and 6? I know dist is output angular folder, but I do not know how it should be. Output files on the server I store in www folder the path are something like var/www/www

There is api.js file with connection:

1 const connection = (closure) => {
2  return MongoClient.connect('mongodb://localhost:27017/mean', (err, db) => 
3     {
4      if (err) return console.log(err);
5      closure(db);
6    });
7 };

Before release, I change line 2 to 'mongodb://IPADDRESS:27017/mean'. IPADDRESS is IP address to my app, I'm not sure but in my opinion, I should not change anything more here.

Thank you for any suggestions.

Upvotes: 0

Views: 56

Answers (1)

Shams Nahid
Shams Nahid

Reputation: 6559

Your default port for the application is 3000. In order to run the application on the universal HTTP port 80, you will need to forward the port 80 to 3000. You can try the following command

sudo /sbin/iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3000

Otherwise, You can also use nginx to redirect traffic from 80 to 3000. Try this.

Keep your code as they are in local machine. Since the database is on the same server, so it won't be a problem.

Upvotes: 1

Related Questions