简体   繁体   中英

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

在此处输入图片说明

FE

在此处输入图片说明

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 (eg npm -> /usr/local/bin/npm ). You can find the absolute path of a command by running which with the name of the command (eg which npm )
  • Run your commands from within bash using /bin/bash -c (eg /bin/bash -c "/usr/local/bin/npm start" )

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.

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