3

I have one simple "Hello World" program in Node.js. I want to run this using batch file.

var http=require("http");

http.createServer(function(request,response){
	response.writeHead(200,{'Content-Type':'text/plain'});
	response.end('Hello World!..\n');
}).listen(8080);
console.log('Server running at http://127.0.0.1:8080/');
I have used this batch file named 'new.bat'.

if not "%minimized%"=="" goto :minimized
set minimized=true
@echo off
start /min cmd /c "C:\Users\USER2\Desktop\webchat\server.js"
goto :EOF
:minimized

please help me.

2 Answers 2

9

You can try this code to create a batch file:

if not "%minimized%"=="" goto :minimized
set minimized=true
@echo off

cd "C:\app path"

start /min cmd /C "nodemon server.js"
goto :EOF
:minimized

to run node.js in background.

Instead of running your app like you are used to like node server.js, you can use nodemon: nodemon server.js

The most simple way you can imagine for a node package:

npm install -g nodemon
Sign up to request clarification or add additional context in comments.

3 Comments

ohh ok i will install it and check.. what is nodemon?
if you made any changes in node.js.you dont have to refresh again.nodemon will auto refresh the file
welcome @nagaraj i think you got idea that how to create batch file
3

server.js

var http=require("http");

http.createServer(function(request,response){
    response.writeHead(200,{'Content-Type':'text/plain'});
    response.end('Hello World!..\n');
}).listen(8080);
console.log('Server running at http://127.0.0.1:8080/');

new.bat enter image description here

if not "%minimized%"=="" goto :minimized
set minimized=true
@echo off
cd "C:\Users\USER2\Desktop\webchat"

start /min cmd /C "nodemon server.js"
goto :EOF
:minimized

Run the application in cmd: run the application in cmd after running the application in cmd the node.js command prompt will look like this.. the application running successfully now you can see the output in browser by setting localhost and the port

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.