How to use ES6 import on nodejs proejct (Node.js/IISNode)

Control Panel V5

First, create a run.cjs file and update this file to import your nodejs site entry point file (server.js) and configure it as the iisnode's entry point ( in web.config).






The cjs file extension is important because it tells Node that this file is not an ES module, as it would expect because of "type": "module" in the package.json. It allows other CommonJS files to include our new file - namely iisnode's interceptor.js. It again imports the server.js which then runs fine as ES module.


Below is a demo entry point file server.js.




import express from 'express';
const app = express();
app.get('/',(req,res) => {
const body = "hello this is a ES6 import demo project"
// Adds header
res.append('Content-Type', 'text/plain;charset=utf-8');
res.append('Connection', 'keep-alive')
res.append('Set-Cookie', 'divehours=fornightly')
res.append('Content-Length', Buffer.byteLength(body, 'utf-8'));
const PORT = process.env.PORT;
app.listen(PORT,() => {
    console.log(`Running on PORT ${PORT}`);


The below code will set your site default routing for iisnode.




<?xml version="1.0" encoding="UTF-8"?>
            <add name="iisnode" path="run.cjs" verb="*" modules="iisnode" />
        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          <action type="Rewrite" url="run.cjs"/>

Import using ES modules: Since Node v8.5, developers have been able to run variations of support for the ES modules specification using the --experimental-modules flag. These modules can be defined in either .mjs files or .js files also by adding { "type": "module" } in the  package.json.



    "name": "index",
    "version": "1.0.0",
    "description": "",
    "main": "server.js",
    "type": "module",
    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "start": "node --experimental-modules server.js"
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
        "express": "^4.18.1"


 Now your site will auto redirect to run.cjs file and auto enter your site entry point file (server.js).