これから『Node.js』が必要になると思われるので
その手始めに
index.js
---------------------------------
'use strict';
var env = process.env.NODE_ENV || 'env1'
if (require.main === module) {
main({ argv: process.argv })
}
main({ argv: process.argv })
}
function main(options) {
var argv = options.argv
var name = argv[2]
var argv = options.argv
var name = argv[2]
if (env === 'env1') {
console.log('皆様こんにちは!')
} else if (env === 'env2') {
console.log('こんにちは ' + name + 'さん!')
} else {
throw new Error('invalid env')
}
}
console.log('皆様こんにちは!')
} else if (env === 'env2') {
console.log('こんにちは ' + name + 'さん!')
} else {
throw new Error('invalid env')
}
}
-------------------------------
NODE_ENV=env1 node index.js 中野
皆様こんにちは!
NODE_ENV=env2 node index.js 中野
こんにちは 中野さん!
example.js
-------------------------------------------------
const http = require('http');
const PORT = 8124;
const PORT = 8124;
http.createServer((request, response) => {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World!\n');
}).listen(PORT);
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World!\n');
}).listen(PORT);
console.log(`Server running at http://localhost:${PORT}/`);
-------------------------------------------------
ブラウザ URL:http:localhost:8124
Hello World!