- create a folder to hold the entire code and navigate into it with console.
$ mkdir your_web_service_name && cd $_
- init npm package
$ npm init -y
- install @tne/express-app
npm install --save @tne/express-app
- Create base folder structure and config files
$ mkdir config src src/routes/
$ touch .gitignore config/development.json config/production.json config/test.json config/keys.json src/index.js src/routes/hello_world.js
- init config files
echo {} | tee config/development.json config/keys.json config/production.json config/test.json
- init
hello_world.js
route copy and paste the following code to toursrc/routes/hello_world.js
file.
const { express } = require('@tne/express-app');
const router = express.Router();
module.exports.default = router
.get('/', (req, res) => res.json({ msg: 'Hello from @tne/express-app library' }));
- init the
index.js
file. copy and paste the following code to toursrc/index.js
file.
const { ExpressAppInterface } = require('@tne/express-app');
ExpressAppInterface.construct({
appPath: __dirname,
appName: 'Your Web Service Name',
port: 3000,
routesFolder: './routes',
});
- update
package.json
file in this moment we are almost ready to begin butpackage.json
file is not ready, so we must to update it in order to prepare to launch the web service.
By pointing the
src/
folder on the main property and adding a start script that leads tosrc/
folder we are ready.
"main": "./src/",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./src/"
},
- init
.gitignore
file. last but not least, you must to ignore following files:
# Logs
logs
*.log
# Dependency directories
node_modules/
# Environment sensitive data
# keys files
keys.json
- final step: first run now we are ready to launch by first time our service by typing in terminal:
npm start