Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Created April 30, 2020 02:35
Show Gist options
  • Save sandrabosk/0a5461c5189913e7e2babd85d03b5c19 to your computer and use it in GitHub Desktop.
Save sandrabosk/0a5461c5189913e7e2babd85d03b5c19 to your computer and use it in GitHub Desktop.
// 1: npm i dotenv
// 2: require packages
const http = require('http');
require('dotenv').config();
const PORT = process.env.PORT || 3000; // You can set default port to 3000 if port is not defined
// 3: create server (and use packages):
const myServer = http.createServer((request, response) => {
console.log(`Success, I'm listening from the port: ${PORT}`);
response.end();
});
// 4: server listens on the port 3000
myServer.listen(process.env.PORT, () => console.log('I am 🏃‍♂️ on port 3000!'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment