首页 > 解决方案 > 如何在 WSL 中切换 Node 项目?

问题描述

使用 开始一个项目后npm init,我如何:a) 切换到另一个项目,b) 回到这个项目并稍后继续?这是否需要某种项目经理?

我试图找到 nodejs 项目经理,虽然我被提到 pm2 并且永远,但是 pm2 似乎超级复杂,我什至不确定它是否能满足我的需要,并且永远运行一个特定的脚本。. . 出色地。. . 永远,这也不是我想要的。

要开始一个项目,我使用:npm init

当然,我可以创建一个项目,但我不知道如何暂时关闭项目和/或稍后切换回它并继续。

标签: node.jswindows-subsystem-for-linux

解决方案


It's really not so complicated. You can create two projects as long as they're in different directories like this.

user@machine:~$ mkdir src
user@machine:~$ cd src
user@machine:~/src$ mkdir project1
user@machine:~/src$ cd project1
user@machine:~/src/project1$ npm init
(...follow the prompts here)
user@machine:~/src/project1$ cd ..
user@machine:~/src$ mkdir project2
user@machine:~/src$ cd project2
user@machine:~/src/project2$ npm init
(...follow the prompts here)
user@machine:~/src/project2$ cd ..

This will leave you with ~/src/project1/package.json and ~/src/project2/package.json

The package.json files are just text files. Neither node nor npm keep the package.json file open.

But, you can open the package.json file in your favourite editor to make changes. Save the changes when you are done. Closing the file again in your editor is up to you, depending on whether or not you want to make further changes.


推荐阅读