code-8
code-8

Reputation: 58662

Configure the npm to start in the background on Mac OS X

Description

I am on a Mac OS X.

Right now, I have almost 10 Laravel/LAMP projects locally, that I ran using vhost configured with Apache. The awesome part about them is even when I restart my Mac or move between networks, or even close the terminal app/tab of my projects, the Apache is still running, all my local sites will still be accessible.


Goal

Now, I am looking to do the same things with my MEAN apps. How would one configure something like that ?

Let's say I have 3 MEAN apps.

Example

App1

App2

App3

I'm opening for anything suggestions at this moment.

Can we configure the npm to start in the background ?


BE/API

enter image description here

FE

enter image description here

Upvotes: 2

Views: 2296

Answers (2)

evanrelf
evanrelf

Reputation: 303

You can use macOS's launchd to run services in the background. There are a couple good GUI apps that make it easier to create launch services:

  • LaunchControl ($10)
  • Lingon ($10) - If you go with Lingon, get Lingon X 5 from the official website instead of Lingon 3 from the Mac App Store; Lingon X 5 is more powerful because it is not limited by Apple's sandboxing.

There's also launched.zerowidth.com, an interactive online tool for creating the .plist files that launchd uses.

launchd.info is also a good resource if you want to set them up manually. Apple's documentation is available too.


If you are having problems with commands not working, I recommend trying these troubleshooting steps:

  • Convert all your commands to use absolute paths (e.g. npm -> /usr/local/bin/npm). You can find the absolute path of a command by running which with the name of the command (e.g. which npm)
  • Run your commands from within bash using /bin/bash -c (e.g /bin/bash -c "/usr/local/bin/npm start")

Upvotes: 2

nerac
nerac

Reputation: 21

One thing you can do is dockerize your applications.

With docker you can run your applications in a light weight virtual machine known as containers in your computer.

This have some advantages, for example, you can run your app with port 80 inside the virtual machine and expose another port to your machine. You can start or stop the container and so forth.

Go to https://www.docker.com/what-docker for more information.

Upvotes: 1

Related Questions