I need to create a bat file to start node server, actually we do it manually but some people need extra help. Let me explain the process:
我需要创建一个bat文件来启动节点服务器,实际上我们手动完成,但有些人需要额外的帮助。让我解释一下这个过程:
- Open CMD
- Go to the path:
cd C://user/folder/server/
- Run the server:
npm start
转到路径:cd C:// user / folder / server /
运行服务器:npm start
It is very simple but I would really like to automate the process to make it faster.
这很简单但我真的希望自动化这个过程以使其更快。
4 个解决方案
#1
4
You can start node.js
server as following .bat
script file by click on it:
您可以通过单击以下.bat脚本文件启动node.js服务器:
@echo off
echo.
set NodePackagesPath=E:\Projects\OpenShift\Materials\Node.jsPackageManager // This is my path, you can edit them
set Path=%NodePackagesPath%\node_modules\.bin;%PATH%
set Path=%NodePackagesPath%;%PATH%
set NODE_PATH=%NodePackagesPath%\node_modules;%NODE_PATH%
set NODE_ENV=production
echo Environment variables are successfully added.
echo.
echo.
echo.
node server.js
#2
4
Know this post is old, but just throwing it out there: I just made a super simple .bat-file to start it:
知道这篇文章是旧的,但只是把它扔出去:我只是制作了一个超级简单的.bat文件来启动它:
cd C:\nodejs
"C:\MongoDB\bin\mongod.exe" --dbpath C:\MongoDB\bin\data\db
node server.js
#3
0
First you must add node.js install folder to path.
Next make a bat file named start.bat
Then, in the file, write
首先,您必须将node.js安装文件夹添加到路径。接下来,创建一个名为start.bat的bat文件然后,在文件中写入
C:/user/folder/server/
npm start
C:/ user / folder / server / npm start
Last click start.bat
最后点击start.bat
#4
0
This not really works: "START /WAIT bitsadmin.exe /transfer "Downloading" http://nodejs.org/dist/v0.8.11/%NODE_EXEC% C:\node-v0.8.11-x86.msi"
这不起作用:“START / WAIT bitsadmin.exe / transfer”正在下载“http://nodejs.org/dist/v0.8.11/%NODE_EXEC% C:\ node-v0.8.11-x86.msi”
I don't know why, but the rest should work:
我不知道为什么,但其余的应该工作:
@echo off
NET SESSION >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
echo This setup needs admin permissions. Please run this file as admin.
pause
exit
)
set NODE_VER=null
set NODE_EXEC=node-v0.8.11-x86.msi
set SETUP_DIR=%CD%
node -v >tmp.txt
set /p NODE_VER=<tmp.txt
del tmp.txt
IF %NODE_VER% NEQ null (
echo INSTALLING node ...
mkdir tmp
IF NOT EXIST tmp/%NODE_EXEC% (
echo Node setup file does not exist. Downloading ...
cd ../bin
START /WAIT bitsadmin.exe /transfer "Downloading" http://nodejs.org/dist/v0.8.11/%NODE_EXEC% C:\node-v0.8.11-x86.msi
rem START /WAIT wget http://nodejs.org/dist/v0.8.11/%NODE_EXEC%
move %NODE_EXEC% %SETUP_DIR%/tmp
)
cd %SETUP_DIR%/tmp
START /WAIT %NODE_EXEC%
cd %SETUP_DIR%
) ELSE (
echo Node is already installed. Proceeding ...
)
#1
4
You can start node.js
server as following .bat
script file by click on it:
您可以通过单击以下.bat脚本文件启动node.js服务器:
@echo off
echo.
set NodePackagesPath=E:\Projects\OpenShift\Materials\Node.jsPackageManager // This is my path, you can edit them
set Path=%NodePackagesPath%\node_modules\.bin;%PATH%
set Path=%NodePackagesPath%;%PATH%
set NODE_PATH=%NodePackagesPath%\node_modules;%NODE_PATH%
set NODE_ENV=production
echo Environment variables are successfully added.
echo.
echo.
echo.
node server.js
#2
4
Know this post is old, but just throwing it out there: I just made a super simple .bat-file to start it:
知道这篇文章是旧的,但只是把它扔出去:我只是制作了一个超级简单的.bat文件来启动它:
cd C:\nodejs
"C:\MongoDB\bin\mongod.exe" --dbpath C:\MongoDB\bin\data\db
node server.js
#3
0
First you must add node.js install folder to path.
Next make a bat file named start.bat
Then, in the file, write
首先,您必须将node.js安装文件夹添加到路径。接下来,创建一个名为start.bat的bat文件然后,在文件中写入
C:/user/folder/server/
npm start
C:/ user / folder / server / npm start
Last click start.bat
最后点击start.bat
#4
0
This not really works: "START /WAIT bitsadmin.exe /transfer "Downloading" http://nodejs.org/dist/v0.8.11/%NODE_EXEC% C:\node-v0.8.11-x86.msi"
这不起作用:“START / WAIT bitsadmin.exe / transfer”正在下载“http://nodejs.org/dist/v0.8.11/%NODE_EXEC% C:\ node-v0.8.11-x86.msi”
I don't know why, but the rest should work:
我不知道为什么,但其余的应该工作:
@echo off
NET SESSION >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
echo This setup needs admin permissions. Please run this file as admin.
pause
exit
)
set NODE_VER=null
set NODE_EXEC=node-v0.8.11-x86.msi
set SETUP_DIR=%CD%
node -v >tmp.txt
set /p NODE_VER=<tmp.txt
del tmp.txt
IF %NODE_VER% NEQ null (
echo INSTALLING node ...
mkdir tmp
IF NOT EXIST tmp/%NODE_EXEC% (
echo Node setup file does not exist. Downloading ...
cd ../bin
START /WAIT bitsadmin.exe /transfer "Downloading" http://nodejs.org/dist/v0.8.11/%NODE_EXEC% C:\node-v0.8.11-x86.msi
rem START /WAIT wget http://nodejs.org/dist/v0.8.11/%NODE_EXEC%
move %NODE_EXEC% %SETUP_DIR%/tmp
)
cd %SETUP_DIR%/tmp
START /WAIT %NODE_EXEC%
cd %SETUP_DIR%
) ELSE (
echo Node is already installed. Proceeding ...
)