I am beginner in nodejs, learning from w3school. So previously I worked in PHP. and the thing is that when I run a simple nodejs program nothing happening in command line and web browser
var http = require('http');
http.createServer(function(request, response) {
request.on('readable', function() {
request.read(); // throw away the data
});
request.on('end', function() {
response.writeHead(200, {
'Content-Type': 'text/plain'
});
response.end('Hello HTTP!');
});
}).listen(8080);
I already use xampp server for apache.
how will run both in system.
If You are using express framework of Node js then try with following code to run NodeJs Program in app.js (main js file of ur NodeJs Application)
const express = require('express')
const app = express()
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(8080, function () {
console.log('Example app listening on port 8080!')
})
then from command prompt run this command
-> node (path to app.js)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With