setup node js express basic setup
npm init -y
npm i express
create node project
#1. server.js
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.status(200).send('Hello World!');
});
var port = process.env.PORT || 3000;
var server = app.listen(port, function() {
console.log('Express server listening on port ' + port);
});
open cmd run server.js
"node server.js"
log:Express server listening on port 3000
& then
open link "http://localhost:3000/" in your browser and show result.
how to use http in development mode for nodejs
var fs = require("fs"),
http = require("https");
var privateKey = fs.readFileSync('sslcert/server.key').toString();
var certificate = fs.readFileSync('sslcert/server.crt').toString();
var credentials = {key: privateKey, cert: certificate};
var server = http.createServer(credentials,function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
});
server.listen(8000);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us